Alexnb | 2 Jul 2008 07:25
Picon

Clearing out a Frame


I have an app that has a base frame, and some other frames inside of that
base frame. My question is if there is some way to clear out the base frame.
Meaning leaving an empty baseframe. See I have a function that pulls up
frames inside that base frame. The problem comes when I hit a button(this
button is the button that first shows the frames inside the base frame,
basically you click it and the internal frames show up.) and then I hit it
again, I get some weird stuff. Okay, this is getting really complicated. I
really just want to know if I can clear out a frame, and still be able to
fill it back up again. If you want ot uunderstand further I'll post the code
at the bottom and just run it, then hit the "Word List" button, then hit it
again, you'll see what I am talking about. 

Here's the code:

from Tkinter import*

class App:
    def __init__(self, parent):
        self.parent = parent
        self.parent.geometry("500x250")

        #----------------------------Contstants for Buttons------------

        button_padx = "2m"
        button_pady = "1m"

        #--------------------------end constants-----------------------

        self.baseContainer = Frame(self.parent)
(Continue reading)

John McMonagle | 2 Jul 2008 08:03
Picon

Re: Clearing out a Frame

Alexnb wrote:
> I have an app that has a base frame, and some other frames inside of that
> base frame. My question is if there is some way to clear out the base frame.
> Meaning leaving an empty baseframe. See I have a function that pulls up
> frames inside that base frame. The problem comes when I hit a button(this
> button is the button that first shows the frames inside the base frame,
> basically you click it and the internal frames show up.) and then I hit it
> again, I get some weird stuff. Okay, this is getting really complicated. I
> really just want to know if I can clear out a frame, and still be able to
> fill it back up again. If you want ot uunderstand further I'll post the code
> at the bottom and just run it, then hit the "Word List" button, then hit it
> again, you'll see what I am talking about. 
> 
Make a list of the widgets when they are created and destroy the widgets
in this list whenever you have to re-define them.

Regards,

John

Your code with mods:

from Tkinter import *

class App:
    def __init__(self, parent):
        self.parent = parent
        self.parent.geometry("500x250")

        self.list_of_widgets = []
(Continue reading)

Alexnb | 2 Jul 2008 08:12
Picon

Re: Clearing out a Frame


Haha!, Brilliant, worked perfectly! Thank you for the help!

John McMonagle-3 wrote:
> 
> Alexnb wrote:
>> I have an app that has a base frame, and some other frames inside of that
>> base frame. My question is if there is some way to clear out the base
>> frame.
>> Meaning leaving an empty baseframe. See I have a function that pulls up
>> frames inside that base frame. The problem comes when I hit a button(this
>> button is the button that first shows the frames inside the base frame,
>> basically you click it and the internal frames show up.) and then I hit
>> it
>> again, I get some weird stuff. Okay, this is getting really complicated.
>> I
>> really just want to know if I can clear out a frame, and still be able to
>> fill it back up again. If you want ot uunderstand further I'll post the
>> code
>> at the bottom and just run it, then hit the "Word List" button, then hit
>> it
>> again, you'll see what I am talking about. 
>> 
> Make a list of the widgets when they are created and destroy the widgets
> in this list whenever you have to re-define them.
> 
> Regards,
> 
> John
> 
(Continue reading)

Michael O'Donnell | 2 Jul 2008 08:37
Picon
Picon
Favicon

Re: Clearing out a Frame

Hi Alex, John,

  No need to collect a list of widgets to delete.  Use pack_slaves()
to find the widgets packed
in the the frame, and then kill each of these:

for wgt in self.mainContainer.pack_slaves():
    wgt.destroy()

All widgets within these widgets will also be destroyed.

Mick

On Wed, Jul 2, 2008 at 8:12 AM, Alexnb <alexnbryan <at> gmail.com> wrote:
>
> Haha!, Brilliant, worked perfectly! Thank you for the help!
>
>
>
> John McMonagle-3 wrote:
>>
>> Alexnb wrote:
>>> I have an app that has a base frame, and some other frames inside of that
>>> base frame. My question is if there is some way to clear out the base
>>> frame.
>>> Meaning leaving an empty baseframe. See I have a function that pulls up
>>> frames inside that base frame. The problem comes when I hit a button(this
>>> button is the button that first shows the frames inside the base frame,
>>> basically you click it and the internal frames show up.) and then I hit
>>> it
(Continue reading)

Alexnb | 3 Jul 2008 07:33
Picon

Issue with the layout of a frame


I am in the middle of writing my first big app. I am having trouble with the
layout of the frames and buttons. In particular, just one frame. I'll post
the code and you can compile it and see what I am talking about. But, when
you do there is a red frame with the button "Define" in it. I want this
frame to be below the yellow and green frame. It has to be a child frame of
a certain parent frame. I can make it work if it is not in that certain
parent frame, but can't seem to when it is. Here's the code, and Ill give
some additional info at the bottom. 

from Tkinter import*
#Now for the class that gets the definitions
from get_defs import*

class App:
    def __init__(self, parent):
        self.parent = parent
        self.parent.geometry("500x250")

        #----------------------------Contstants for Buttons------------

        button_padx = "2m"
        button_pady = "1m"

        #--------------------------end constants-----------------------

        self.baseContainer = Frame(self.parent)
        self.baseContainer.pack(side=TOP, fill = BOTH, expand=NO)

        #the Top Frame with all the buttons
(Continue reading)

Guilherme Polo | 3 Jul 2008 14:10
Picon
Gravatar

Re: Issue with the layout of a frame

On Thu, Jul 3, 2008 at 2:33 AM, Alexnb <alexnbryan <at> gmail.com> wrote:
>
> I am in the middle of writing my first big app. I am having trouble with the
> layout of the frames and buttons. In particular, just one frame. I'll post
> the code and you can compile it and see what I am talking about. But, when
> you do there is a red frame with the button "Define" in it. I want this
> frame to be below the yellow and green frame. It has to be a child frame of
> a certain parent frame. I can make it work if it is not in that certain
> parent frame, but can't seem to when it is. Here's the code, and Ill give
> some additional info at the bottom.

I'm sure you can manage to post a much smaller code that shows your
problem. This may also help you understanding the problem, and your
chances of getting help will increase at the same time.

>
> from Tkinter import*
> #Now for the class that gets the definitions
> from get_defs import*
>
> class App:
>    def __init__(self, parent):
>        self.parent = parent
>        self.parent.geometry("500x250")
>
>        #----------------------------Contstants for Buttons------------
>
>        button_padx = "2m"
>        button_pady = "1m"
>
(Continue reading)

John McMonagle | 4 Jul 2008 00:30
Picon

Re: Issue with the layout of a frame

Alexnb wrote:

> 
> there is a button towards the bottom called the defineIt button. this is the
> button in the red frame. If you look right above the big comment called
> constants for buttons, that frame called definebuttonF is the red frame. I
> need the parent to be the mainContainer frame. However, if you make it the
> baseContainer frame. that is what I want it to look like. See if you can
> make it work. I haven't been able to yet. I know this may seem like it would
> take a while; but I really would like it if someone helped. 
> 

Make another frame, which is a child of self.mainContainer and pack the
LEFT and RIGHT frames in it.  Now your frame with the red background is
packed underneath and is a child of mainContainer.

eg:

    def define_Frame(self):

        #Destroy all child widgets
        self.destroyMainChildren()

        myMessage="Please type in all the words that you would like  to
define"
        Label(self.mainContainer, text=myMessage,
                    justify=LEFT).pack(side=TOP, anchor=N)

        f = Frame(self.mainContainer)
        f.pack(side=TOP, expand=YES, fill=BOTH)
(Continue reading)

Alexnb | 4 Jul 2008 01:16
Picon

Taking a Text() widget and saving it to a .txt file


I don't really know if this is possible, but it seems like there should be an
easy way. If I have a text widget:

text = Text(parent)

and I want to take what is in there and save it has a text file. How would I
go about doing this. Also, if it matters, I would like to keep it in the
same format as the textbox. 
--

-- 
View this message in context: http://www.nabble.com/Taking-a-Text%28%29-widget-and-saving-it-to-a-.txt-file-tp18269937p18269937.html
Sent from the Python - tkinter-discuss mailing list archive at Nabble.com.
Bob Greschke | 4 Jul 2008 02:32

Text() scrolling, but Canvas() not on OSX

My Text() widgets with scrollbars (all Tkinter, not PMW widgets)  
scroll using the two-finger scroll method on my MacBook trackpad, but  
my Canvas()'s with scrollbars don't.  Is there some bind I should be  
doing, or is this just another OSX X11 "feature"?

Typical Text():
     Sub = Frame(LFrm)
     LTxt = Txt["HELP"] = Text(Sub, width = HELPWidth, height =  
HELPHeight, \
             wrap = WORD, font = HELPFont, relief = SUNKEN)
     LTxt.pack(side = LEFT, fill = BOTH, expand = YES)
     Sb = Scrollbar(Sub, orient = VERTICAL, command = LTxt.yview)
     Sb.pack(side = RIGHT, fill = Y)
     LTxt.configure(yscrollcommand = Sb.set)
     Sub.pack(side = TOP, fill = BOTH, expand = YES)

Typical Canvas():
     SSSub = Frame(SSub)
     LCan = Can["PTRD"] = Canvas(SSSub, bg = Clr["B"], bd = 0, width =  
700, \
             height = 500, scrollregion = (0, 0, 700, 500))
     LCan.pack(side = LEFT, fill = BOTH, expand = YES)
     PTRDScroll = Sb = Scrollbar(SSSub, orient = VERTICAL, command =  
LCan.yview)
     Sb.pack(side = RIGHT, fill = Y, expand = NO)
     LCan.configure(yscrollcommand = Sb.set)
     SSSub.pack(side = TOP, fill = BOTH, expand = YES)

Thanks!
(Continue reading)

Cameron Laird | 4 Jul 2008 02:57

Re: Taking a Text() widget and saving it to a .txt file

On Thu, Jul 03, 2008 at 04:16:23PM -0700, Alexnb wrote:
			.
			.
			.
> I don't really know if this is possible, but it seems like there should be an
> easy way. If I have a text widget:
> 
> text = Text(parent)
> 
> and I want to take what is in there and save it has a text file. How would I
> go about doing this. Also, if it matters, I would like to keep it in the
> same format as the textbox. 
			.
			.
			.
You'll want to start by reading <URL: 
http://www.pythonware.com/library/tkinter/introduction/x8369-methods.htm >,
and especially about get():

    text.get("1.0", "end")

Gmane