Displaying variable on a label Tkinter python 2.7 -


i read similiar questions here couldn't fix code, ask.

i'm working on little program gui, press button, adds 1 variable, press second button, subtract, press third button, prints current value of variable. want print variable on gui, on label, i've read how , thought got it, when went run code label not working. runs though, no error message.

from tkinter import *  class experiment:       def __init__(self, master):         global students         frame = frame(master)         frame.pack()          self.addbutton = button(frame, text="add student", command=self.addstudent, bg="black", fg="white")         self.addbutton.grid(row=0, column=1, sticky = e)          self.subbutton = button(frame,text="subtract student", command=self.subtractstudent, bg="black", fg="white")         self.subbutton.grid(row=0, column=2, sticky = e)          self.checkbutton = button(frame,text="check record", command=self.checkstudentrec, bg="black", fg="white")         self.checkbutton.grid(row=0, column=3, sticky= e )          self.quitbutton = button(frame,text="quit", command=frame.quit)         self.quitbutton.grid(row=2, column=3, sticky=w)          self.label1 = label(frame, textvariable = students)         self.label1.grid(row=2, column=1)      def addstudent(self):         global students         students = students + 1         print "\n student added"     def subtractstudent(self):         global students         students = students - 1         print "\n student deleted"     def checkstudentrec(self):         print students         print "\n student record found"  root = tk() students = 0 b = experiment(root) root.mainloop() 

label textvariable parameter expect special kind of tkinter/tcl variables. these ones can traced, in meaning piece of program can subscribe value , notified when changes.

thus, initializing students intvar , adapting increment code should job.

def addstudent(self):     global students     students.set(students.get() + 1)  #(...) students = intvar() 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -