ich bin gerade dabei in ein Menü ein "Listen-" und "Bildermodus" zu intergrieren. Der Code lautet wie folgt:
Code: Alles auswählen
from Tkinter import *
import os
def breakout():
root.destroy()
os.system("start "" breakout.bat")
def pong():
root.destroy()
os.system("start "" pong.bat")
def snake():
root.destroy()
os.system("start "" snake.bat")
def list():
breakout_btn_img.destroy()
pong_btn_img.destroy()
snake_btn_img.destroy()
list_btn.destroy()
image_btn.grid(row=0, column=0)
breakout_btn.grid(row=1, column=0)
pong_btn.grid(row=2, column=0)
snake_btn.grid(row=3, column=0)
def image():
breakout_btn.destroy()
pong_btn.destroy()
snake_btn.destroy()
image_btn.destroy()
breakout_btn_img.grid(row=1, column=0)
pong_btn_img.grid(row=2, column=0)
snake_btn_img.grid(row=3, column=0)
root = Tk()
root.title("TheArcadeMachine")
root.resizable(False, False)
list_btn = Button(root, width=47, command=list, relief=SOLID, borderwidth=1, text="list mode")
breakout_img = PhotoImage(file="../img/breakout.gif")
breakout_btn_img = Button(root, width=333, height=127, image=breakout_img, command=breakout, relief=FLAT)
breakout.image = breakout_img
pong_img = PhotoImage(file="../img/pong.gif")
pong_btn_img = Button(root, width=333, height=127, image=pong_img, command=pong, relief=FLAT)
pong.image = pong_img
snake_img = PhotoImage(file="../img/snake.gif")
snake_btn_img = Button(root, width=333, height=127, image=snake_img, command=snake, relief=FLAT)
snake.image = snake_img
image_btn = Button(root, width=47, command=image, relief=SOLID, borderwidth=1, text="picture mode")
breakout_btn = Button(root, width=47, command=breakout, relief=FLAT, text="Breakout")
pong_btn = Button(root, width=47, command=pong, relief=FLAT, text="Pong")
snake_btn = Button(root, width=47, command=snake, relief=FLAT, text="Snake")
list_btn.grid(row=0, column=0)
breakout_btn_img.grid(row=1, column=0)
pong_btn_img.grid(row=2, column=0)
snake_btn_img.grid(row=3, column=0)
root.mainloop()
Code: Alles auswählen
"C:\Program Files (x86)\Python27\python.exe" D:/Tim/Dokumente/PythonProjects/TheArcadeMachine/data/src/main.py
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Program Files (x86)\Python27\lib\lib-tk\Tkinter.py", line 1542, in __call__
return self.func(*args)
File "D:/Tim/Dokumente/PythonProjects/TheArcadeMachine/data/src/main.py", line 27, in image
breakout_btn_img.grid(row=1, column=0)
File "C:\Program Files (x86)\Python27\lib\lib-tk\Tkinter.py", line 2029, in grid_configure
+ self._options(cnf, kw))
TclError: bad window path name ".56902040"
Desweiteren wäre ich über Kritik sehr erfreut
Grüße aus Hannover
GuardDog