求助如何给tkinter设置全背景图,代码如下
from tkinter import*from PIL import Image, ImageTk
class Window(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.master = master
self.pack(fill=BOTH, expand=1)
self.imgs = {
"微信": "wechat.png",
"支付宝": "alipay.png",
}
variable = StringVar()
variable.set("支付方式")
menu = OptionMenu(root, variable, *self.imgs.keys(), command=self.set_image)
menu.place(x=800,y=150)
text_label=Label(root,text="欢迎进入支付系统",font=("华康少女字体",20),fg="green").place(x=740,y=10)
canvas_root=root.Canvas(root,width=1600,height=900)
im_root=get_image('bg.jpg',1600,900)
canvas_root.create_image(800,450,image=im_root)
canvas_root.pack()
def set_image(self, val):
load = Image.open(self.imgs.get(val))
render = ImageTk.PhotoImage(load)
img = Label(self, image=render)
img.image = render
img.place(x=450, y=200)
def get_image(filename,width,height):
im = Image.open(filename).resize((width,height))
return ImageTk.PhotoImage(im)
root = Tk()
app = Window(root)
root.title("支付系统")
root.geometry("1600x900")
root.resizable(width=False, height=False)
root.mainloop()
https://blog.csdn.net/rikkatakanashi/article/details/83719068
度娘一搜就是答案 笨鸟学飞 发表于 2021-2-28 00:49
https://blog.csdn.net/rikkatakanashi/article/details/83719068
度娘一搜就是答案
这个已经成功了,主要我要在上面设置选项,根据选项出现图片
页:
[1]