小玩意儿
Posted sikongji-yeshan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了小玩意儿相关的知识,希望对你有一定的参考价值。
from tkinter import * from tkinter import messagebox def CloseWindow(): messagebox.showinfo(title ="警告",message = "不许关闭,好好回答!") #messagebox.showinfo(title = "警告",message = "不许关闭,好好回答!") return def Love(): #顶级窗口 love = Toplevel(window) love.geometry("300x150+320+150") love.title("好巧,我也是") label1 = Label(love,text = "好巧,我也是",font = ("微软雅黑",20)) label1.pack()#显示按钮 btn1 = Button(love,text = "确定",width = 10,height = 2,command = CloseAllWindow) btn1.pack() def DontLove(): # 顶级窗口 nolove = Toplevel(window) nolove.geometry("300x150+320+150") nolove.title("再考虑考虑") label1 = Label(nolove, text="再考虑考虑呗!", font=("微软雅黑", 20)) label1.pack() # 显示按钮 btn2 = Button(nolove, text="好的,我再考虑考虑", width=15, height=3, command=nolove.destroy) btn2.pack() nolove.protocol("WM_DELETE_WINDOW",Closenolove) #用户关闭窗口触发的事件 def Closenolove(): messagebox.showinfo(title = "在考虑考虑呗!",message = "再考虑考虑呗") #return #关闭所有窗口 def CloseAllWindow(): window.destroy() #创建窗口 window = Tk() #窗口标题 window.title("无敌的我是多么的自信") #窗口大小 窗口位置 小写的x window.geometry("400x400+300+50") #protocol用户关闭窗口触发的事件 window.protocol("WM_DELETE_WINDOW",CloseWindow) #标签控件 label = Label(window,text = "hello boy",font = ("微软雅黑",15),fg = "red") #定位 网格式布局 sticky对齐方式 N S W E 北南西东(上下左右) label.grid(row = 0,column = 0,sticky = W) label_1 = Label(window,text = "Are you ok ?",font = ("微软雅黑",15)) label_1.grid(row = 1,column = 1,sticky = E ) #显示图片 photo = PhotoImage(file="./cc.png") imageLable = Label(window,image = photo) #columnspan 组件所跨越的列数 imageLable.grid(row = 2, columnspan = 2,sticky = W) #按钮控件 btn = Button(window,text = "好的",width = 15,height = 2,command = Love) btn.grid(row = 3,column = 0,sticky = W) btn1 = Button(window,text = "不好",command = DontLove) btn1.grid(row = 3,columnspan = 2,sticky = E) #显示窗口 消息循环 window.mainloop()
以上是关于小玩意儿的主要内容,如果未能解决你的问题,请参考以下文章