python的GUI
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import tkinter #导入TKinter模块
from PIL import ImageTk, Image
ytm = tkinter.Tk()#创建Tk对象
ytm.withdraw
ytm.title("login") # 设置窗口标题
ytm.geometry("300x300") # 设置窗口尺寸
#背景
canvas = tkinter.Canvas(ytm, width=600,height=600,bd=0, highlightthickness=0)#创建画布,bd-背景色
canvas.pack()
imgpath = 'C:/Users/lenovo/Pictures/Saved Pictures/timg.jfif'
img = Image.open(imgpath)
photo = ImageTk.PhotoImage(img)
canvas.create_image(300, 300, image=photo)#使用create_image将图片添加到Canvas组件中
label=tkinter.Label(ytm, text="用户名") # 标签
label.pack()#指定包管理器放置组件
canvas.create_window(50, 50, width=70, height=20,window=label)#添加标签到画布上
entry=tkinter.Entry(ytm,insertbackground='blue', highlightthickness =2)
entry.pack()
canvas.create_window(150, 50, width=100, height=20,window=entry)#添加输入框到画布上
def getuser():
user = entry.get() # 获取文本框内容
print(user)#输出到控制台
button=tkinter.Button(ytm, text="登录", command=getuser) # command绑定获取文本框内容方法
button.pack()
canvas.create_window(250, 50, width=50, height=20,window=button)#添加按钮到画布上
# 进入消息循环
ytm .mainloop()
# Fpath = filedialog.askopenfile()
# print(Fpath)