Related content:
Starting Time: 2018-03-04 22:18
MessageBox
- Description: MessageBox is a message box, dialog box in Tkinter
- Use:
- Importing modules: Import Tkinter.messagebox
- Select the mode of the message box:
- Prompt message box: "Return" OK "
Tkinter.messagebox.showinfo (message box title, prompt content)
- Message warning Box "return" OK ":
Tkinter.messagebox.showwarning ( message box title, warning content)
- Error message box "Return" OK ":
Tkinter.messagebox.showerror (message box title, error content)
- dialog box:
- Ask confirmation dialog [return "Yes", "no"]:
Tkinter.messagebox.askquestion (message box title, prompt content)
- Confirm/Cancel dialog box [return True False]:
Tkinter.messagebox.askokcancel (message box title, prompt content)
Yes/No dialog box "return True False":
Tkinter.messagebox.askyesno (message box title, prompt content)
Retry/Cancel dialog box: "Return value: True False"
Tkinter.messagebox.askretrycancel (title, hint content)
- yes \ No \ Cancel dialog box: "Return value: Yes: True No: False cancel: None":
Tkinter.messagebox.askyesnocancel (title, hint content)
fromTkinterImport*ImportTkinter.messageboxdefInfo_warn_err (): a=tkinter.messagebox.showinfo ("my title","My tips 1") Print(a) a=tkinter.messagebox.showwarning ("my title","My Tips 2") Print(a) a=tkinter.messagebox.showerror ("my title","My Tips 3") Print(a)defFunc2 (): a=tkinter.messagebox.askyesno ("my title","My tips 1") Print(a) a=tkinter.messagebox.askokcancel ("my title","My Tips 2") Print(a) a=tkinter.messagebox.askquestion ("my title","My Tips 3") Print(a) a=tkinter.messagebox.askretrycancel ("my title","My tips 4") Print(a) a=tkinter.messagebox.askyesnocancel ("my title","My Tips 5") Print(a)#This is used to demonstrate how to use the dialog box ifTkinter.messagebox.askyesno ("my title","Confirm Close Window!"): Root.destroy () root=Tk () btn=button (root,text="Message , warning, error message box", command=info_warn_err) btn1=button (root,text="dialog Box", command=Func2) btn.pack () Btn1.pack () Root.mainloop ()
FileDialog:
- Description: FileDialog is a file dialog box in Tkinter
- Use:
- Importing modules: Import Tkinter.filedialog
- Format of the Select File dialog box:
- Tkinter.filedialog.asksaveasfilename (): Choose what file name to save, return file name
- Tkinter.filedialog.asksaveasfile (): Choose what file to save, create the file and return the file stream object
- Tkinter.filedialog.askopenfilename (): Choose what file to open, return file name
- Tkinter.filedialog.askopenfile (): Select what file to open, return IO Stream object
- Tkinter.filedialog.askdirectory (): Select directory, return directory name
- Tkinter.filedialog.askopenfilenames (): Select to open multiple files and return multiple filenames as tuples
- Tkinter.filedialog.askopenfiles (): Choose to open multiple files to return multiple IO Stream objects as a list
ImportTkinter.filedialog fromTkinterImport*deffunc1 (): a=tkinter.filedialog.asksaveasfilename ()#return file name Print(a) a=tkinter.filedialog.asksaveasfile ()#The file is created Print(a) a=tkinter.filedialog.askopenfilename ()#return file name Print(a) a=tkinter.filedialog.askopenfile ()#returns a file stream object Print(a) a=tkinter.filedialog.askdirectory ()#Return directory name Print(a) a=tkinter.filedialog.askopenfilenames ()#can return multiple file names Print(a) a=tkinter.filedialog.askopenfiles ()#multiple file Stream objects Print(a) root=Tk () btn1=button (root,text="Click", command=func1) Btn1.pack () Root.mainloop ()
Tkinter of Python:gui Learning notes, FileDialog