from tkinter import*
from pygame.locals import *
from random import randint
import pygame
import time
from snake2electricboogaloo import snake_electric_boogaloo
window = Tk()
window.title("Snake 2 Launcher")
window.geometry('600x600')
def callback():
snake_electric_boogaloo()
B = Button(window, text ="Run Game", justify=CENTER, command = callback)
B.place(x = 50,y=50)
window.mainloop()
此代码不是调用游戏,这是针对学校项目的,我花了太多时间在此上。名称都正确,游戏与GUI在同一个文件中。
答案 0 :(得分:0)
我不能为您提供太多帮助,因为我不知道您的snake_electric_boogaloo代码,但是我可以告诉您,从tkinter的按钮或按键调用回调时,必须向该函数添加一个额外的参数。您需要将def callback():
替换为def callback(event):
您编辑的代码应类似于:
from tkinter import*
from pygame.locals import *
from random import randint
import pygame
import time
from snake2electricboogaloo import snake_electric_boogaloo
window = Tk()
window.title("Snake 2 Launcher")
window.geometry('600x600')
def callback(event):
snake_electric_boogaloo()
B = Button(window, text ="Run Game", justify=CENTER, command = callback)
B.place(x = 50,y=50)
window.mainloop()
我希望这会有所帮助!