Jack Frye Jack Frye - 1 year ago 105
Python Question

Producing Empty TKinter GUIs

The following TKinter code is producing an empty TK window. I cannot figure out why. I am packing everything appropriately. The map is the first Frame that is supposed to come up but when it launches there is only the top bar without any image or button. I also tried launching the hydra level frame first and it produces the same results.

#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)

#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


#show the frame from the dictionary in the tkinter window
def show(self, controller):
frame = self.frames[controller]
print(isinstance(frame, Frame))

def open(self):

def switch(self):

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))

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))

Answer Source

I am packing everything appropriately

No, you are not. You aren't calling pack, place or grid on theMaporHydra` objects.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download