Я выполнял Gui несколько windows квест, но у Tkinter, похоже, нет Tk. Моя полная ошибка:
Traceback (most recent call last):
File "/Users/connorsmacbook/PycharmProjects/2.8/2.8 Internal/TextTypers 2.2.py", line 6, in <module>
class TextTypers(tk.TK):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter/__init__.py", line 2101, in __getattr__
return getattr(self.tk, attr)
AttributeError: '_tkinter.tkapp' object has no attribute 'TK'
Мой код:
from tkinter import *
tk=Tk()
# Classes
class TextTypers(tk.TK):
def __init__(self, *args, **kwargs): # Runs when our class is called and allows almost anything to be passed
tk.Tk.__init__(self, *args, **kwargs) # Initialise Tk
window = tk.Frame(self) # Creates the container the windows/frames will populate
window.pack()
self.frames = {} # Creates a dictionary for the frames
frame = MenuScreen(window, self)
self.frames[MenuScreen] = frame
frame.grid(row=0, column=0, sticky="nswe")
self.show_frame(MenuScreen) # Shows the menu screen as this is initialising
def show_frame(self, cont):
frame = self.frames[cont] # Grabs value of self.frames and puts in in frame
frame.tkraise() # Raises frame to the front
class MenuScreen(tk.frame): # Inherits everything from the frame
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent) # Inherits from main class
label = tk.Label(self, text="Menu")
label.pack()
run = TextTypers()
run.mainloop()
Если бы какие-то мастера могли помочь, я был бы признателен :).