1, create a GUI window, the implementation of the code call.

2. Write the click trigger function to realize the confession procedure.

The specific code is as follows:

from tkinter import * from tkinter import messagebox def closeWindow(): Messagebox.showinfo (title=" warning ",message=" do not close ") # messagebox.showerror(title=" warning ",message=" do not close ") Return # click like to trigger the method def Love(): # Top-Level window love = Toplevel(window) lov.geometry ("300x100+520+260") lov.title ("300x100+520+260") label = label (love,text =" BTN = Button(love,text=" ok ",width=10,height=2,command=closeAllWindow) btn.pack() Loe. protocol("WM_DELETE_WINDOW",closeLove) def closeLove(): return # closeAllWindow(): # destroy window.destroy() def olove (): No_love = Toplevel(window) no_lov.geometry ("300x100+520+260") no_lov.title (" Think again ") label = Label(no_love,text=" think about it ",font=(" Microsoft Yahei ",25)) label.pack() BTN = Button(no_love,text=" ok ",width=10,height=2,command=no_love.destroy) btn.pack() no_love.protocol("WM_DELETE_WINDOW",closeNoLove) def closeNoLove(): NoLove () # create parent window = Tk() #Tk is a class # window.title(" Do you like me? Window. Geometry ('+500+240' Window. protocol("WM_DELETE_WINDOW",closeWindow) # label = label (window,text="hey, ",font=(" Microsoft Yahei ",15),fg='red') # Grid (Row = 0,column = 0,sticky = W) Label1 = label (Window,text=" Do you like me?" Grid (row = 1,column = 1,sticky = E) # sticky = PhotoImage(file = "./cc.png") imageLable = Label(window,image = photo) # ColumnSpan imagelable.grid (row = 2, Columnspan =2) BTN = Button(window,text=" like ",width=15,height=2,command=Love) BTN 3,column = 0, column = 0, column = W) btn1 = Button(window,text=" not like ",command=noLove) btn1. Sticky = E) # Display window, also called message loop window.mainloop()Copy the code

Instance extension:

Copy # package Operation # Install PyInstaller # CMD enter PIP install PyInstaller # Shift + right-click the folder and click here to open the command window # PyInstaller-f -w love.py // Package program # From tkinter import * #__all__=[a,b] #from tkinter import messageBox # Messagebox.showinfo (title=" warning ",message =" go back, must select one ") return # def Love(): Geometry = Toplevel("300x100+250+260") love.title(" I love you, too ") label = label (love, text = "I love you, too!") ,font = (" Microsoft Yahei ",20)) label.pack() BTN = Button(love,text = "hello ",width = 10,height = 2,command= closeallWindow) btn.pack() Loe. protocol("WM_DELETE_WINDOW", closelove) def closelove(): return def closeallWindow (): Def noLove(): No_love = Toplevel(window) no_love.geometry("300x100+520+260") no_love.title(" 选 选") label = Toplevel(window) no_love Label(no_love,text=" ") ,font = (" Microsoft Yahei ",25)) label.pack() BTN = Button(no_love,text=" ok ", width=10, Height =2,command=no_love.destroy) btn.pack() no_love.protocol("WM_DELETE_WINDOW",closenolove) # def closenolove(): #return noLove() # create window = Tk() # window.title(" Do you like me? Geometry ("380x420+500+240") # love. Title (" ha ") BTN =Button(" text=" ") # Geometry ("+500+240") window.protocol("WM_DELETE_WINDOW",closeWindow) # Grid (row = 0, column = 0) label = label (window,text = "Do you like me? ") ,font = (" Microsoft Yahei ",30)) label. Grid (row = 1, Photo = PhotoImage(file = "./123.png") imageLable = Label(window,image = photo) Imagelable.grid (row =2, columnspan =2) # select * from imagelable.grid (row =2, columnspan =2) BTN. Grid (row=3,column=0,sticky= W) Btn.grid (row=3,column=1,sticky= E)Copy the code

Need to take the code directly, there is a problem to find me to solve it! The word inside is can change at will for other words, can modify by oneself ha!

I am white and white I, a love to share knowledge of the program yuan ❤️

If you have no contact with the programming section of the friends see this blog, find do not understand or want to learn Python, you can directly leave a message + private I ducky [thank you very much for your likes, collection, attention, comments, one button four connect support]