jeudi 17 septembre 2015

Issues with creating two checkboxes in a gui

I am doing a project for school, but I am stuck with the creation of multiple checkboxes. I copy/pasted some code and messed around with, trying to get two checkboxes but I was unable to do so. The checkboxes use the same variable to tick/untick(I know this). I am unable to find a way to get a second variable to allow the second checkbox to be ticked or unticked depending on whether the first is unticked or ticked, respectively. Thanks in advance.

from tkinter import * root = Tk() root.title("Payroll") root.resizable(width=FALSE, height=FALSE) class App: def __init__(self,master): root.minsize(width=500, height=500) root.maxsize(width=500, height=500) self.var = IntVar() frame = Frame(master) frame.grid() f2 = Frame(master,width=200,height=100) f2.grid(row=0,column=1) btnSalary = Checkbutton(frame,text='Salary',variable=self.var,command=self.fx) btnWage = Checkbutton(frame,text='Wage',variable=self.var,command= self.fx) btnSalary.grid(row=0,column=0) btnWage.grid(row=2,column=0) msg1="Wage" self.v= Message(f2,text=msg1) msg2="Salary" self.v= Message(f2,text=msg2) def fx(self): if self.var.get(): self.v.grid(column=1,row=0,sticky=N) else: self.v.grid_remove() app = App(root)
root.mainloop()




Aucun commentaire:

Enregistrer un commentaire