|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
from tkinter import *
root = Tk()
root.title("居中的窗口")
screenWidth = root.winfo_screenwidth() # 获取显示区域的宽度
screenHeight = root.winfo_screenheight() # 获取显示区域的高度
width = 600 # 设定窗口宽度
height = 400 # 设定窗口高度
left = (screenWidth - width) / 2
top = (screenHeight - height) / 2
# 宽度x高度+x偏移+y偏移
# 在设定宽度和高度的基础上指定窗口相对于屏幕左上角的偏移位置
root.geometry("%dx%d+%d+%d" % (width, height, left, top))
def love():
master = Toplevel()
master.title("居中的窗口")
screenWidth = master.winfo_screenwidth()
screenHeight = master.winfo_screenheight()
width = 600
height = 500
left = (screenWidth - width) / 2
top = (screenHeight - height) / 2
master.geometry("%dx%d+%d+%d" % (width, height, left, top))
w = Label(master, image=lphoto)
w.pack()
Button(master,text='确定',command=master.quit).pack()
mainloop()
def dislove():
master = Toplevel()
# disphoto = PhotoImage(file=r"E:\P.py\课堂练习.py\tkinter\眼瞎.png")
# textlabel=Label(master,text='你怕是眼瞎').pack()
master.title("让你认清自己!!!")
screenWidth = master.winfo_screenwidth()
screenHeight = master.winfo_screenheight()
width = 600
height = 380
left = (screenWidth - width) / 2
top = (screenHeight - height) / 2
master.geometry("%dx%d+%d+%d" % (width, height, left, top))
w = Label(master, image=disphoto)
w.pack()
Button(master,text='确定',command=master.quit).pack()
mainloop()
textlable = Label(root,text='祢豆子真漂亮')
textlable.pack()
lphoto = PhotoImage(file=r"E:\P.py\课堂练习.py\tkinter\喜欢.png")
disphoto = PhotoImage(file=r"E:\P.py\课堂练习.py\tkinter\眼瞎.png")
photo = PhotoImage(file=r"E:\P.py\课堂练习.py\tkinter\1.png")
w = Label(root, image=photo)
w.pack()
button1=Button(root,text='喜欢',command=love)
button2=Button(root,text='不喜欢',command=dislove)
button1.pack()
button2.pack()
mainloop()
为啥love和第三love的窗口需要点击两下button才能生效
这样即可: from tkinter import *
root = Tk()
root.title("居中的窗口")
screenWidth = root.winfo_screenwidth() # 获取显示区域的宽度
screenHeight = root.winfo_screenheight() # 获取显示区域的高度
width = 600 # 设定窗口宽度
height = 400 # 设定窗口高度
left = (screenWidth - width) / 2
top = (screenHeight - height) / 2
# 宽度x高度+x偏移+y偏移
# 在设定宽度和高度的基础上指定窗口相对于屏幕左上角的偏移位置
root.geometry("%dx%d+%d+%d" % (width, height, left, top))
def love():
master = Toplevel()
master.title("居中的窗口")
screenWidth = master.winfo_screenwidth()
screenHeight = master.winfo_screenheight()
width = 600
height = 500
left = (screenWidth - width) / 2
top = (screenHeight - height) / 2
master.geometry("%dx%d+%d+%d" % (width, height, left, top))
w = Label(master, image=lphoto)
w.pack()
Button(master, text='确定', command=master.quit).pack()
def dislove():
master = Toplevel()
# disphoto = PhotoImage(file=r"E:\P.py\课堂练习.py\tkinter\眼瞎.png")
# textlabel=Label(master,text='你怕是眼瞎').pack()
master.title("让你认清自己!!!")
screenWidth = master.winfo_screenwidth()
screenHeight = master.winfo_screenheight()
width = 600
height = 380
left = (screenWidth - width) / 2
top = (screenHeight - height) / 2
master.geometry("%dx%d+%d+%d" % (width, height, left, top))
w = Label(master, image=disphoto)
w.pack()
Button(master, text='确定', command=master.quit).pack()
textlable = Label(root, text='祢豆子真漂亮')
textlable.pack()
lphoto = PhotoImage(file=r"1.png")
disphoto = PhotoImage(file=r"1.png")
photo = PhotoImage(file=r"1.png")
w = Label(root, image=photo)
w.pack()
button1 = Button(root, text='喜欢', command=love)
button2 = Button(root, text='不喜欢', command=dislove)
button1.pack()
button2.pack()
mainloop()
|
|