[Tkinter-discuss] Hiding and unhiding frames and/or widgets in general

Chris Nethery clnethery at juno.com
Sun Aug 22 08:24:26 CEST 2004


First, I recall now that I neglected to thank everyone for their help, concerning my last question.  The last two months have been extraordinarily busy, although that's a poor excuse for bad manners, so thank you all, belatedly, for your assistance.

I am back again, with another (possibly silly) question regarding hiding and unhiding windows.  I notice that toplevel windows have the ability to be "withdrawn" or "deiconified" in order to be hidden from view.  My widgets are not toplevel widgets, so I'm unclear about whether or not I can use these methods or not.  Either way, I am trying (unsuccessfully) to accomplish something similar, in that I would like to destroy or withdraw an entryfield widget if a comboBox is displayed, and visa versa.  Also, if neither an entryfield or a comboBox is displayed, nothing should be displayed in the same spot.

The following code illustrates, to some degree, what I'm trying to accomplish.  But you'll note that the code has other problems as well:


import Pmw
from Tkinter import *

root = Tk()
Pmw.initialise(root)

class Stuff:

    def __init__(self, root):
        self.root = root

        self.mainframe = Frame(self.root)
        self.mainframe.pack(fill='both', expand=1, padx=5, pady=5)

        self.choices = [
            '',
            'Select the entryField...',
            'Select the entryField again...',
            'Select the entryField yet again...',
                       ]
        self.choices2 = [
            '',
            'Select the comboBox...',
            'Select the comboBox again...',
            'Select the comboBox yet again...',
                        ]
        self.stuffList = [
            '',
            'item 1',
            'item 2',
            'item 3',
            'item 4',
            'item 5',
            'item 6',
            'item 7',
            'item 8',
            'item 9',
            'item 10',
                         ]

        self.cBox = Pmw.ComboBox(
            self.mainframe,
            listheight=225,
            selectioncommand=self.createEntryField,
            entry_width=28, labelmargin=1, labelpos='w', label_text='Select stuff:', scrolledlist_items=self.choices+self.choices2)
        self.cBox.pack()

        self.eFrame = Frame(self.mainframe, borderwidth=0, width=200, height=22, relief=GROOVE)
        self.eField = Pmw.EntryField(
            self.eFrame,
            labelpos=W,
            label_text='Enter Stuff:',
            labelmargin=2,
            entry_width=12,
            validate = None,
            )
        self.eField.pack()

        self.cFrame = Frame(self.mainframe, borderwidth=0, width=200, height=22, relief=GROOVE)
        self.cBox2 = Pmw.ComboBox(
                self.cFrame,
                listheight=165,
                entry_width=12,
                labelmargin=9,
                labelpos='w',
                label_text='Stuff:',
                scrolledlist_items=self.stuffList
                )
        self.cBox2.pack()
        

    def createEntryField(self, hello):
        for item in self.choices:
            if self.cBox.component('entryfield').component('entry').get() == item:
                self.cFrame.lower()
                self.eFrame.lift()
                self.eFrame.place(relx=0.7, rely=0.08, anchor=NW)
            else:
                self.eFrame.lower()
                self.cFrame.lift()
                self.cFrame.place(relx=0.7, rely=0.08, anchor=NW)


if __name__=='__main__':
    stuff = Stuff(root)
    root.mainloop()


Any ideas?  Thanking you in advance,

Christopher Nethery





More information about the Tkinter-discuss mailing list