Python Forum
[Tkinter] New to Tkinter -- Does not recognize "Frame" as attribute.
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
Reply
#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.
Reply
#3
Thanks ever so much. I should have figured that out, but I'm still kind of a novice.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] TKinter Remove Button Frame Nu2Python 8 818 Jan-16-2024, 06:44 PM
Last Post: rob101
  TKinter Widget Attribute and Method Quick Reference zunebuggy 3 788 Oct-15-2023, 05:49 PM
Last Post: zunebuggy
  [Tkinter] Help running a loop inside a tkinter frame Konstantin23 3 1,449 Aug-10-2023, 11:41 AM
Last Post: Konstantin23
  tkinter mapview in a frame janeik 2 1,245 Jun-22-2023, 02:53 PM
Last Post: deanhystad
  tkinter AttributeError: 'GUI' object has no attribute pfdjhfuys 3 1,452 May-18-2023, 03:30 PM
Last Post: pfdjhfuys
  [Tkinter] Trouble changing Font within tkinter frame title AnotherSam 1 4,009 Sep-30-2021, 05:57 PM
Last Post: menator01
  tkinter frame camera opencv Nick_tkinter 9 5,322 Mar-21-2021, 06:41 PM
Last Post: Nick_tkinter
  [Tkinter] Tkinter delete values in Entries, when I'm changing the Frame robertoCarlos 11 5,647 Jul-29-2020, 07:13 PM
Last Post: deanhystad
  How to disable focus on Frame in Tkinter? szafranji 1 2,973 May-13-2020, 10:45 PM
Last Post: DT2000
  [Tkinter] Tkinter bringing variables from 1 frame to another zukochew 6 12,414 Dec-26-2019, 05:27 AM
Last Post: skm

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020