Bottom Page

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.
Yoriz wrote May-05-2019, 08:30 AM:
Please post all code, output and errors (in it's entirety) between their respective tags. I did it for you this time, Here are instructions on how to do it yourself next time.
Quote
#2
Why not use a tutorial such as this one?
Quote
#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()
Quote
#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
Quote
#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.
Quote
#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
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  PyQT5 : Unable to Create Another Dialog While One is Open iMuny 3 383 Jul-17-2019, 11:40 AM
Last Post: iMuny
  [PyQt] PyQt4 handle dynamic checkbox click littleGreenDude 1 1,578 Dec-27-2018, 09:17 PM
Last Post: littleGreenDude
  [Tkinter] Completing Action when CheckBox is Checked Anysja 2 942 Aug-02-2018, 04:38 PM
Last Post: Anysja
  TreeviewWith CheckBox issac_n 0 1,518 Jun-05-2018, 03:56 PM
Last Post: issac_n
  Displaying error in QTableview and with Checkbox in Column under macOsX nieselfriem 1 2,334 Mar-19-2017, 10:43 PM
Last Post: nilamo

Forum Jump:


Users browsing this thread: 1 Guest(s)