Python Forum
[Tkinter] Unable to create checkbox and select at run time
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Unable to create checkbox and select at run time
#1
Hello All,

I am facing some challenge with my user interface:

def PopUp():
        pop = Tk()
        count =output1.split()

        for  i in range(0,len(count)):
                var=[]

                l=Checkbutton(pop,text=output1.split()[i],variable=var.append(i)).grid(row=i+1,sticky=W)
This will print output as:
Output:
x ABC x CDE x DEF
Depending upon how many values are there in count

Now when user selects ABC and DEF that is checkbox 1 and 3,wanted to take these values and perform certain operations or all three checkbox.
so wanted to understand how can store the values that user selected and then utilize them further.
Reply
#2
Why not use a tutorial such as this one?
Reply
#3
You could store the data in a dictionary
import tkinter as tk


class MainFrame(tk.Frame):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.checkbuttons = {'ABC': tk.IntVar(),
                             'CDE': tk.IntVar(),
                             'EFG': tk.IntVar()}
        
        for key, value in self.checkbuttons.items():
            ctrl = tk.Checkbutton(self, text=key, variable=value)
            ctrl.pack()
        
        self.button = tk.Button(
            self, text='Checkbutton values', command=self.on_button)
        self.button.pack(pady=15)
        self.pack()

    def on_button(self):
        print('checkbutton values')
        for key, value in self.checkbuttons.items():
            print(f'{key}: {value.get()}')


if __name__ == '__main__':
    app = tk.Tk()
    main_frame = MainFrame()
    app.mainloop()
Reply
#4
Hello Yoriz,

I am not clear here,this list gets created at run time and then I want to translate this list into set of checkboxes,which user can interact with and then process the user input further.

Thanks and Regards
Tej Gandhi
Reply
#5
Give an a few examples of what the list could contain and in what way you plan to react on the result of the checkbutton choices.
Reply
#6
Hello Yoriz,all,

It creates a list of running processes or something similar to that,the we determine which processes the user has selected and provide more description and details on it.

Thanks and Regards
Tej Gandhi
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] choose checkbox devilonline 1 1,239 Feb-17-2023, 01:23 PM
Last Post: Axel_Erfurt
  [Tkinter] Dynamic checkbox treeview issue OogieM 8 4,818 Mar-20-2022, 02:10 PM
Last Post: OogieM
  tkinter change the text of the checkbox zazas321 1 3,753 Sep-17-2021, 06:19 AM
Last Post: zazas321
  How to get the value of a checkbox scratchmyhead 4 2,982 May-14-2020, 02:56 PM
Last Post: scratchmyhead
  Tkinter checkbox value scratchmyhead 5 3,592 May-09-2020, 11:44 PM
Last Post: menator01
  TreeviewWith CheckBox issac_n 1 7,683 Mar-08-2020, 06:51 AM
Last Post: shamnadinn
  Tkinter Checkbox niro_one 1 2,310 Jan-13-2020, 11:31 AM
Last Post: joe_momma
  PyQT5 : Unable to Create Another Dialog While One is Open iMuny 3 3,816 Jul-17-2019, 11:40 AM
Last Post: iMuny
  [PyQt] PyQt4 handle dynamic checkbox click littleGreenDude 1 6,532 Dec-27-2018, 09:17 PM
Last Post: littleGreenDude
  [Tkinter] Completing Action when CheckBox is Checked Anysja 2 7,890 Aug-02-2018, 04:38 PM
Last Post: Anysja

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020