我不知道为什么这不起作用。我在mac上使用python 3。我试过了 label.image但它不起作用。这是我的代码:
File=open("/Users/user/Desktop/Python/File.txt")
FileContents=File.readlines()
ThingAmount=Team[0]
ActiveThing=Team[1]
ActiveThingImage=PhotoImage("/Users/user/Desktop/Python/"+ActiveThing+"/"+ActiveThing+".gif")
EnemyThingImage=PhotoImage("/Users/user/Desktop/Python/Enemy/EnemyThing.gif")
ActiveThingLabel=Label(window,image=ActiveThingImage)
ActiveThingLabel.image=ActiveThingImage
ActiveThingLabel.place(x=0,y=0)
EnemyThingLabel=Label(window,image=EnemyThingImage)
EnemyThingLabel.place(x=100,y=100)
答案 0 :(得分:0)
图像可能有点棘手 - 但我想我可以帮助解决2个问题!
创建图像
- 醇>
如何从某个文件夹中加载一堆图像。
1:
获取图像的按钮可能有点棘手(你需要一种2层的方法),但更改图像很容易。
x_image = 'x.png'
o_image = 'o.png'
...然后
x_image_for_button = PhotoImage(file=x_image)
o_image_for_button = PhotoImage(file=o_image)
然后.....
button = tk.Button(self.controller, image=o_image_for_button, command=lambda: command_or_something)
button.config(width="40", height="40")
button.place(x=5, y=5)
(添加自我。或root。等)
现在您所做的只是更改图片:
button.set(image=o_image_for_button)
#on second thought... maybe use `button.config(image=o_image_for_button)` insted
2:
image_folder = 'theme_icons'
if self.controller.background_theme == '1':
image_pathway = 'classic'
elif self.controller.background_theme == '2':
image_pathway = 'blue1'
elif self.controller.background_theme == '3':
image_pathway = 'blue2'
elif self.controller.background_theme == '4':
image_pathway = 'classic_blue'
self.house_image_d = os.path.join(image_folder, image_pathway, 'Image1.png')
self.line_d = os.path.join(image_folder, image_pathway, 'Image2.png')
self.house_image = tk.PhotoImage(file=self.house_image_d)
self.my_line = tk.PhotoImage(file=self.line_d)