0
次のTKinterコードは、空のTKウィンドウを生成しています。なぜ私は理解できません。私はすべてを適切に梱包しています。マップは最初に出てくるはずのフレームですが、起動すると画像やボタンのないトップバーのみが表示されます。私はまた、最初にヒドラレベルのフレームを起動しようとし、それは同じ結果を生成します。空のTKinter GUIの作成
#class inspired by sentdex SeaOfBTCapp
#see https://www.youtube.com/watch?v=A0gaXfM1UN0&index=2&list=PLQVvvaa0QuDclKx-QpC9wntnURXVJqLyk
class GUI_Control(Tk):
def __init__(self, player, control, *args, **kwargs):
self.player = player
self.delegate = control
Tk.__init__(self, *args, **kwargs)
self.window = Frame(self)
self.window.pack()
#specify frames that can be loaded into the TK window. These will be defined in subclasses of Tk.Frame
self.frames = {}
#setup initial frame, all frames take GUI_Control as a listener to control event handling with window changes
level_keys = [Map, Hydra_Level]
for level in level_keys:
frame = level(self.window, self)
self.frames[level] = frame
self.show(Map)
#show the frame from the dictionary in the tkinter window
def show(self, controller):
frame = self.frames[controller]
print(isinstance(frame, Frame))
frame.tkraise()
def open(self):
self.mainloop()
def switch(self):
pass
class Map(Frame):
def __init__(self, master, controller, *args, **kwargs):
Frame.__init__(self, master)
self.controller = controller
# define map gui here
self.map_picture = PhotoImage(file=r"images/archipelago.gif")
self.image = Label(self, image=self.map_picture)
self.image.pack(padx=10, pady=10)
self.go_to_button = Button(self, text="Go to", command=lambda: self.controller.show(Hydra_Level))
self.go_to_button.pack()
class Hydra_Level(Frame):
def __init__(self, master, controller, *args, **kwargs):
Frame.__init__(self, master)
self.listener = master
self.go_to_button = Button(self, text="Back to map", command=lambda: self.controller.show(Map))
self.go_to_button.grid(row=0)
あなたは正しいです。私の修正をありがとう –