Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 [Tkinter] New to Tkinter -- Does not recognize "Frame" as attribute.
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.increase_button = tkinter.Button(self)
        self.increase_button["text"] = "Increase"
        self.increase_button["command"] = self.increase_value

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

    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)
C:\Users\carys\AppData\Local\Programs\Python\Python37\python.exe "C:/Users/carys/My first project/" Traceback (most recent call last): File "C:/Users/carys/My first project/", line 1, in <module> import tkinter File "C:\Users\carys\My first project\", line 3, in <module> class Application(tkinter.Frame): AttributeError: module 'tkinter' has no attribute 'Frame' Process finished with exit code 1
The answer is simple: don't name your program 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.
Thanks ever so much. I should have figured that out, but I'm still kind of a novice.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  TKinter GUI / Pandas Data frame Loop NSearch 0 30 11 hours ago
Last Post: NSearch
  [Tkinter] changing the frame colour nick123 2 205 May-14-2019, 02:48 PM
Last Post: nick123
  [Tkinter] create and insert a new frame on top of another frame atlass218 4 226 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 257 Mar-29-2019, 03:24 PM
Last Post: Axel_Erfurt
  [Tkinter] not resize a frame Scorpio 2 195 Mar-13-2019, 11:24 PM
Last Post: Scorpio
  video player inside a frame/panel in python raspberry pi desktop application MATHEWS 1 331 Dec-12-2018, 11:42 AM
Last Post: Larz60+
  [Tkinter] Frame in canvas wont fill AceScottie 0 380 Nov-06-2018, 02:00 PM
Last Post: AceScottie
  [Tkinter] Notebook accessing a specific tab using a button from a toplevel frame honestie 8 2,240 Sep-12-2018, 01:51 AM
Last Post: honestie
  [Tkinter] Tkinter bringing variables from 1 frame to another zukochew 5 994 Aug-01-2018, 12:17 PM
Last Post: Windspar
  [Tkinter] Treeview automatically adjust it's size when pack inside frame Prince_Bhatia 1 3,175 Jul-25-2018, 03:24 AM
Last Post: Larz60+

Forum Jump:

Users browsing this thread: 1 Guest(s)