我一直在尝试添加图像,以便我的按钮位于图像的顶部,但只能使图像完全覆盖所有内容,或者强制图像位于按钮覆盖的水平部分下方.
以下是相关代码:
class MainMenu(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.master = master
self.initUI()
def initUI(self):
self.master.title("Adventure")
bg = PhotoImage(file="Background-gif.gif")
newGameButton = Button(self, text="New Game", height=2, width=20, command=self.newGame)
newGameButton.pack(side=TOP, pady=50)
loadGameButton = Button(self, text="Load Game", height=2, width=20, command=self.loadGame)
loadGameButton.pack(side=TOP)
quitButton = Button(self, text="Quit", height=2, width=20, command=self.close)
quitButton.pack(side=TOP, pady=50)
label = Label(self, image=bg)
label.image = bg
label.pack(fill=BOTH, expand=1)
self.pack()
Run Code Online (Sandbox Code Playgroud)
非常感谢.
我试图在 Python 中制作一个“游戏”,用户可以在其中输入一个命令。但是,我不知道您是否可以将该输入作为函数名称。这是我目前的努力:
def move():
print("Test.")
if __name__ == "__main__":
input("Press enter to begin.")
currentEnvironment = getNewEnvironment(environments)
currentTimeOfDay = getTime(timeTicks, timeOfDay)
print("You are standing in the {0}. It is {1}.".format(currentEnvironment, currentTimeOfDay))
command = input("> ")
command()
Run Code Online (Sandbox Code Playgroud)
在这里,输入是移动,因为我想尝试调用该函数(作为潜在的最终用户可能)。但是,我收到以下错误:
Traceback (most recent call last):
File "D:\Text Adventure.py", line 64, in <module>
command()
TypeError: 'str' object is not callable
Run Code Online (Sandbox Code Playgroud)
我想知道是否有任何方法可以让用户在游戏中“移动”,该程序通过调用“移动”函数来实现。