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
  [Tkinter] changing the frame colour nick123 2 132 May-14-2019, 02:48 PM
Last Post: nick123
  [Tkinter] create and insert a new frame on top of another frame atlass218 4 165 Apr-18-2019, 05:36 PM
Last Post: atlass218
  [PyQt] I build and install PyQT for python2 but it not recognize in python nadavvin 7 179 Mar-29-2019, 03:24 PM
Last Post: Axel_Erfurt
  [Tkinter] not resize a frame Scorpio 2 145 Mar-13-2019, 11:24 PM
Last Post: Scorpio
  video player inside a frame/panel in python raspberry pi desktop application MATHEWS 1 283 Dec-12-2018, 11:42 AM
Last Post: Larz60+
  [Tkinter] Frame in canvas wont fill AceScottie 0 322 Nov-06-2018, 02:00 PM
Last Post: AceScottie
  [Tkinter] Notebook accessing a specific tab using a button from a toplevel frame honestie 8 1,809 Sep-12-2018, 01:51 AM
Last Post: honestie
  [Tkinter] Tkinter bringing variables from 1 frame to another zukochew 5 848 Aug-01-2018, 12:17 PM
Last Post: Windspar
  [Tkinter] Treeview automatically adjust it's size when pack inside frame Prince_Bhatia 1 2,566 Jul-25-2018, 03:24 AM
Last Post: Larz60+
  Second frame (listbox) in GUI dimvord 4 730 Jul-04-2018, 03:40 PM
Last Post: dimvord

Forum Jump:


Users browsing this thread: 1 Guest(s)