【发布时间】:2020-04-22 09:41:51
【问题描述】:
我正在做一个战舰游戏和下面的一个函数,它执行以创建一个以爆炸图像作为背景的新按钮。我正在使用 Mac & python 3.7
global redraw_gameboard
global Player
global AI_player
script_dir = os.path.dirname(__file__)
rel_path = "explode.png"
image = ImageTk.PhotoImage(file=os.path.join(script_dir, rel_path))
new_button = Button(redraw_gameboard,
height = 2,
width = 4,
command= already_shot,
image=image)
new_button.grid(row = row, column = column)
这是即将发布的内容:
【问题讨论】:
-
尝试使用枕头模块
-
如果代码在函数内部,则需要保留对
image的引用。尝试添加new_button.image = image。 -
@acw1668 谢谢哥们,它终于对我有用了!!
标签: python tkinter tk tkinter-canvas