Get the App
SLTechnology News&Howtos  ›  Development  › 

How to create a python_tkinter pop-up dialog box

Shulou Source: shulou.com Published: 2022-06-01 04:42:12 10月03日 Update

This article mainly shows you "how to create a python_tkinter pop-up dialog box", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to create a python_tkinter pop-up dialog box" this article.

Tkinter provides three modules to create pop-up dialog windows: (using modules that must be imported separately)

Example of 1.messagebox message dialog box: askokcancel

Import tkinter# Import message dialog sub-module import tkinter.messagebox# create main window root = tkinter.Tk () # set window size root.minsize (300300) # declare function def okqqq (): # pop-up dialog box result = tkinter.messagebox.askokcancel (title = 'title ~', message=' content: want to eat?) # return value is True or False print (result) # add button btn1 = tkinter.Button (root,text = 'ok',command = okqqq) btn1.pack () # join message loop root.mainloop () example: askquestion

Import tkinter# Import message dialog sub-module import tkinter.messagebox# create main window root = tkinter.Tk () # set window size root.minsize (300300) # declare function def question (): # pop-up dialog box result = tkinter.messagebox.askquestion (title = 'title', message=' content: have you eaten yet?) # return value is: yes/no print (result) # add button btn1 = tkinter.Button (root,text = 'question',command = question) btn1.pack () # join message loop root.mainloop () example: askretrycancel (retry)

Import tkinter# Import message dialog sub-module import tkinter.messagebox# create main window root = tkinter.Tk () # set window size root.minsize (300300) # declare function def retry (): # pop-up dialog box result = tkinter.messagebox.askretrycancel (title = 'title', message=' content: the girl rejected you!?) # return value: True or False print (result) # add button btn1 = tkinter.Button (root,text = 'retry',command = retry) btn1.pack () # join message loop root.mainloop () example: askyesno

# declare function def yesno (): # pop-up dialog box result = tkinter.messagebox.askyesno (title = 'title', message=' content: do you like me?) # return value: True or False print (result) # add button btn1 = tkinter.Button (root,text = 'yesno',command = yesno) btn1.pack () example: showerror (error)

# declare function def error (): # pop-up dialog box result = tkinter.messagebox.showerror (title = 'error!' , message=' content: your age does not meet the requirements.') # return value: ok print (result) # add button btn1 = tkinter.Button (root,text = 'error',command = error) btn1.pack () example: showwarning (warning)

# declare function def warning (): # pop-up dialog box result = tkinter.messagebox.showwarning (title = 'error!' Message=' content: no entry under the age of 18.') # return value is: ok print (result) # add button btn1 = tkinter.Button (root,text = 'warning',command = warning) btn1.pack () example: showinto (information prompt)

# declare function def info (): # pop-up dialog box result = tkinter.messagebox.showinfo (title = 'informational hint!' , message=' content: your girlfriend received a lipstick of unknown origin! # return value is: ok print (result) # add button btn1 = tkinter.Button (root,text = 'info',command = info) btn1.pack () 2.simpledialog simple message dialog example: asksting (get string)

Import tkinter# import sub-module import tkinter.simpledialog# create main window root = tkinter.Tk () # set window size root.minsize (300300) # create function def askname (): # get string (title, prompt Initial value) result = tkinter.simpledialog.askstring (title = 'get information', prompt=' please enter name:', initialvalue = 'you can set initial value') # print content print (result) # add button btn = tkinter.Button (root,text = 'get user name', command = askname) btn.pack () # join message loop root.mainloop () example: askinteger (get integer)

Import tkinter# Import message dialog sub-module import tkinter.simpledialog# create main window root = tkinter.Tk () # set window size root.minsize (300300) # create function def askage (): # get integer (title, prompt Initial value) result = tkinter.simpledialog.askinteger (title = 'get information', prompt=' please enter age:', initialvalue = '18') # print content print (result) # add button btn = tkinter.Button (root,text =' get age', command = askage) btn.pack () # join message loop root.mainloop () example: askfloat (get floating point)

Import tkinter# Import message dialog sub-module import tkinter.simpledialog# create main window root = tkinter.Tk () # set window size root.minsize (300300) # create function def askheight (): # get floating point data (title, prompt Initial value) result = tkinter.simpledialog.askfloat (title = 'get information', prompt=' please enter height (in meters):', initialvalue = '18.0') # print content print (result) # add button btn = tkinter.Button (root,text =' get height' Command = askheight) btn.pack () # join the message loop root.mainloop () these are all the contents of the article "how to create a python_tkinter pop-up dialog box" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Dialogue content dialog box message function button example module title information size loop box prompt age article input character string floating point Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei MySQL MariaDB Apple Linux