【发布时间】:2020-08-17 21:19:58
【问题描述】:
我正在尝试将图片插入 tkinter 按钮
这是我的代码:
from tkinter import *
import tkinter as tk
from PIL import Image,ImageTk,ImageOps
class main_class(tk.Tk):
def __init__(self):
self.window = tk.Tk()
self.window.geometry("1920x1080")
self.window.configure(background='grey')
#opening play pic and resizing it to fit into button
self.play_pic = Image.open("play_pic.jpg")
self.play_pic_size = (11,49)
self.play_pic = ImageOps.fit(self.play_pic,self.play_pic_size,Image.ANTIALIAS)
self.play_pic = ImageTk.PhotoImage(self.play_pic)
#play button
self.play_button = Button(self.window,image=self.play_pic,command = self.play,height =11 ,width = 49).place(x=800,y = 180)
self.window.mainloop()
def play(self):
print('Everything is working fine so far')
#creating an object
object = main_class()
object.play()
结果应该是这样的:
这是“play_pic.jpg”,以备不时之需:
非常感谢任何帮助!
【问题讨论】:
-
stackoverflow.com/questions/52250213/… 回答你的问题了吗?
-
@ThierryLathuille 不幸的是没有
-
@Renaud 也不起作用:C
-
你在这两个地方都改了吗?你是否也改变了 y 值?
标签: python image user-interface tkinter python-imaging-library