直接上代码,包括背景图。
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 printkey(event):
print('你按下了: ' + event.char)
if event.char=='q':#按键盘q
print('你按下了: ' + event.char)
root.attributes("-fullscreen", False)
mainloop()
if event.char=='f':#按键盘f
print('你按下了: ' + event.char)
#root.attributes('-zoomed', True)
root.attributes("-fullscreen", True)
w = root.winfo_screenwidth()
h = root.winfo_screenheight()
#ry("%dx%d" %(w,h))
#root.attributes("-topmost",True)
mainloop()
def main():
'''
注意: 背景图片im_root/im_root1这些,必须得是在主界面函数里进行加载,换个地方不行了,不知道为啥
'''
root.attributes("-fullscreen", True) # substitute `Tk` for whatever your `Tk()` object is called
root.title("背景图展示")
ry('400x600+180+100')
#sizable(False, False)
# 设置背景图片
canvas_root = tk.Canvas(root, width=400, height=600)
im_root = get_img('./bg2.jpeg', 400, 600)
ate_image(0,0, anchor='nw', image=im_root)
canvas_root.pack()
# label 中设置图片
#im_root1 = get_img('./bg1.jpeg', 100, 40)
#img_label = Label(root, text='欢迎使用J波检测', image=im_root1)
#img_label.place(x=3, y=3, width=100, height=40)
#实例化一个输入框
#entry = Entry(root)
#给输入框绑定按键监听事件<Key>为监听任何按键 <Key-x>监听其它键盘,如大写的A<Key-A>、回车<Key-Return>
#entry.bind('<Key>', printkey)
#显示窗体
#entry.pack()
root.bind('<Key>', printkey)
mainloop()
if __name__ == '__main__':
root = Tk()
main()
本文发布于:2024-02-01 08:28:15,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170674729735242.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |