Jan-02-2019, 10:40 PM
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.
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