直接上代码:
from tkinter import *
import tkinter as tk
from PIL import ImageTk
from PIL import Image
def get_img(filename, width, height):
im = Image.open(filename).resize((width, height))
im = ImageTk.PhotoImage(im)
return im
def main():
'''
注意: 背景图片im_root/im_root1这些,必须得是在主界面函数里进行加载,换个地方不行了,不知道为啥
'''
root = Tk()
root.geometry('1000x600+180+100')
root.resizable(False, False)
# 设置背景图片
canvas_root = tk.Canvas(root, width=1000, height=600)
im_root = get_img('./background/background.jpg', 1000, 600)
canvas_root.create_image(500, 300, image=im_root)
canvas_root.pack()
# label 中设置图片
im_root1 = get_img('./background/one.jpg', 100, 40)
img_label = Label(root, text='欢迎使用J波检测', image=im_root1)
img_label.place(x=3, y=3, width=100, height=40)
mainloop()
if __name__ == '__main__':
main()
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有