Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] New to Tkinter -- Does not recognize "Frame" as attribute.
#1
I am a novice with Python, and with Tk in particular. I have been taking an online course and am just getting into GUI using tkinter. I copied the attached code from the manual for the online course. The code is supposed to print a number, then either double it or halve it depending on the button pressed.

I am getting an error message indicating that "Frame" is not an attribute of tkinter. I must be missing something, but I can't find anything in the documentation that helps.

Any assistance would be appreciated.


import tkinter

class Application(tkinter.Frame):
    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.pack()

        self.increase_button = tkinter.Button(self)
        self.increase_button["text"] = "Increase"
        self.increase_button["command"] = self.increase_value
        self.increase_button.pack(side="right")

        self.increase_button = tkinter.Button(self)
        self.increase_button["text"] = "Decrease"
        self.increase_button["command"] = self.decrease_value
        self.increase_button.pack(side="left")

    def increase_value(self):
        global mainval
        mainval *= 2
        print (mainval)

    def decrease_value(self):
        global mainval
        mainval /= 2
        print (mainval)

mainval = 1.0
root = tkinter.Tk()
app = Application(master=root)
app.mainloop()
Error:
C:\Users\carys\AppData\Local\Programs\Python\Python37\python.exe "C:/Users/carys/My first project/tkinter.py" Traceback (most recent call last): File "C:/Users/carys/My first project/tkinter.py", line 1, in <module> import tkinter File "C:\Users\carys\My first project\tkinter.py", line 3, in <module> class Application(tkinter.Frame): AttributeError: module 'tkinter' has no attribute 'Frame' Process finished with exit code 1
Quote
#2
The answer is simple: don't name your program tkinter.py. Rename it to something else. If there is still a file such as tkinter.pyc or tkinter.pyo in the same directory, remove it as well.
Quote
#3
Thanks ever so much. I should have figured that out, but I'm still kind of a novice.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  video player inside a frame/panel in python raspberry pi desktop application MATHEWS 1 125 Dec-12-2018, 11:42 AM
Last Post: Larz60+
  [Tkinter] Frame in canvas wont fill AceScottie 0 173 Nov-06-2018, 02:00 PM
Last Post: AceScottie
  [Tkinter] Notebook accessing a specific tab using a button from a toplevel frame honestie 8 898 Sep-12-2018, 01:51 AM
Last Post: honestie
  [Tkinter] Tkinter bringing variables from 1 frame to another zukochew 5 512 Aug-01-2018, 12:17 PM
Last Post: Windspar
  [Tkinter] Treeview automatically adjust it's size when pack inside frame Prince_Bhatia 1 990 Jul-25-2018, 03:24 AM
Last Post: Larz60+
  Second frame (listbox) in GUI dimvord 4 502 Jul-04-2018, 03:40 PM
Last Post: dimvord
  [Tkinter] output "os" in frame m_clayton 6 693 May-29-2018, 12:14 AM
Last Post: m_clayton
  [Tkinter] Adding a Frame litaboss 2 538 Mar-02-2018, 06:04 AM
Last Post: litaboss
  [Tkinter] Frame size only works if frame is empty(Solved) Tuck12173 7 1,019 Jan-29-2018, 10:44 PM
Last Post: Larz60+
  tkinter frame sizing problems Lux 0 1,146 Aug-26-2017, 06:09 PM
Last Post: Lux

Forum Jump:


Users browsing this thread: 1 Guest(s)