About Lesson
In this TKinter lesson we want to learn about creating TKinter Multi ChoiceBox, basically it is a kind of messagebox with multiple options.
This is the complete code for this lesson.
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 37 38 39 |
import tkinter as tk from tkinter import ttk from tkinter import messagebox as msg class Window(tk.Tk): def __init__(self): super(Window, self).__init__() self.title("MultiChoiceBox in TKinter") self.minsize(350,350) self.wm_iconbitmap("myicon.ico") self.create_button() def create_button(self): self.btn = ttk.Button(self, text = "Open Choice Box", command = self.choice_box) self.btn.grid(column = 1, row = 1) def choice_box(self): answer = msg.askyesnocancel("Multi Choice Box Title", "Do You Want To Quite!") if answer == True: self.quit() window = Window() window.mainloop() |
basically we have created a button and i want to connect the multi choicebox with the button.
1 2 |
self.btn = ttk.Button(self, text = "Open Choice Box", command = self.choice_box) self.btn.grid(column = 1, row = 1) |
This is our method for creating of multi choicebox, we can use askyesnocancel() for multi choicebox.
1 2 3 4 5 |
def choice_box(self): answer = msg.askyesnocancel("Multi Choice Box Title", "Do You Want To Quite!") if answer == True: self.quit() |
Run the complete code and this is the result.