Python Forum
[Tkinter] Unable to create checkbox and select at run time - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [Tkinter] Unable to create checkbox and select at run time (/thread-18081.html)



Unable to create checkbox and select at run time - tej7gandhi - May-05-2019

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.


RE: Unable to create checkbox and select at run time using ptkinter - Gribouillis - May-05-2019

Why not use a tutorial such as this one?


RE: Unable to create checkbox and select at run time - Yoriz - May-05-2019

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()



RE: Unable to create checkbox and select at run time - tej7gandhi - May-05-2019

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


RE: Unable to create checkbox and select at run time - Yoriz - May-05-2019

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.


RE: Unable to create checkbox and select at run time - tej7gandhi - May-05-2019

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