In this Python TKinter article i want to show you How To Create MultiChoiceBox In Python TKinter.
if you are interested in Python GUI Development, you can check the below links.
Also you can read more articles on Python GUI Development
1: PyQt5 GUI Development Tutorials
2: Pyside2 GUI Development Tutorials
3: wxPython GUI Development Tutorials
4: Kivy GUI Development Tutorials
This is the complete code for How To Create MultiChoiceBox In Python TKinter
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
from tkinter import * from tkinter import ttk from tkinter import messagebox as msg class Root(Tk): def __init__(self): super(Root, self).__init__() self.title("Tkinter Multi Choice Box") self.minsize(600,400) self.wm_iconbitmap('icon.ico') self.button() def button(self): self.btn = ttk.Button(self, text = "Open Multi Choice Box", command = self.choicBox) self.btn.grid(column = 0, row = 0) def choicBox(self): answer = msg.askyesnocancel("Multi Choice Box", "Are You Sure You Really Want To Quite?") if answer == True: self.quit() root = Root() root.mainloop() |
These are the imports that we need for this article, basically it is tkinter library, also we are
going to import ttk from tkinter with messagebox from tkinter .
1 2 3 |
from tkinter import * from tkinter import ttk from tkinter import messagebox as msg |
So at the top we have our Root class that inherits from TK class, and in that class we have
added some requirements for the window like title, size and also icon.
1 2 3 4 5 6 7 8 |
class Root(Tk): def __init__(self): super(Root, self).__init__() self.title("Tkinter Multi Choice Box") self.minsize(600,400) self.wm_iconbitmap('icon.ico') self.button() |
This is the button method, because i want when a user click this button iam going to show a
MultiChoiceBox with different choices. you can see that we have connected this method with
our def choiceBox() method.
1 2 3 |
def button(self): self.btn = ttk.Button(self, text = "Open Multi Choice Box", command = self.choicBox) self.btn.grid(column = 0, row = 0) |
This is the process of MultiChoiceBox creation.
1 2 3 4 5 |
def choicBox(self): answer = msg.askyesnocancel("Multi Choice Box", "Are You Sure You Really Want To Quite?") if answer == True: self.quit() |
Run the code and this will be the result
Also you can watch the complete video for this article
Subscribe and Get Free Video Courses & Articles in your Email