Bug in Tkinter?

tre17 at student.canterbury.ac.nz tre17 at student.canterbury.ac.nz
Tue Aug 31 04:45:53 EDT 1999


Have a look at the following code.  It should produce a window
containing two radio buttons, one of which is active when the program
starts.  But it does not!  Now remove the comments, so that there is a 
permanent reference to StringVar instance, and now it works?

This is running Python 1.5.2 from the Debian package `python-tk 1.5.2-5'
under Debian 2.2 (potato).

=====================
#!/usr/bin/python

from Tkinter import *
import sys

class Foo(Frame):
    def __init__(self, master):
        Frame.__init__(self, master, relief='raised', bd=1)
        mode = StringVar()
        self.b1 = Radiobutton(self, text='Foo',
                              variable=mode, value='foo',
                              command=self.foo)
        self.b2 = Radiobutton(self, text='Bar',
                              variable=mode, value='bar',
                              command=self.bar)
        self.b1.pack(side='left', fill='x', expand=1)
        self.b2.pack(side='right', fill='x', expand=1)
        mode.set('bar')
        print sys.getrefcount(mode)
        #d['mode'] = mode
        #print sys.getrefcount(mode)

    def foo(self):
        print 'foo'

    def bar(self):
        print 'bar'

root = Tk()
d = {}
f = Foo(root)
f.pack()
root.mainloop()
=====================

Any comments?

--
Tim Evans




More information about the Python-list mailing list