Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #21223 > unrolled thread
| Started by | John Salerno <johnjsal@gmail.com> |
|---|---|
| First post | 2012-03-04 23:12 -0800 |
| Last post | 2012-03-05 12:25 -0500 |
| Articles | 13 — 5 participants |
Back to article view | Back to comp.lang.python
Tkinter: Why aren't my widgets expanding when I resize the window? John Salerno <johnjsal@gmail.com> - 2012-03-04 23:12 -0800
Re: Tkinter: Why aren't my widgets expanding when I resize the window? Rick Johnson <rantingrickjohnson@gmail.com> - 2012-03-05 05:09 -0800
Re: Tkinter: Why aren't my widgets expanding when I resize the window? John Salerno <johnjsal@gmail.com> - 2012-03-05 09:31 -0800
Re: Tkinter: Why aren't my widgets expanding when I resize the window? Rick Johnson <rantingrickjohnson@gmail.com> - 2012-03-05 11:03 -0800
Re: Tkinter: Why aren't my widgets expanding when I resize the window? John Salerno <johnjsal@gmail.com> - 2012-03-05 14:07 -0800
Re: Tkinter: Why aren't my widgets expanding when I resize the window? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-03-06 01:10 +0000
Re: Tkinter: Why aren't my widgets expanding when I resize the window? John Salerno <johnjsal@gmail.com> - 2012-03-05 17:53 -0800
Re: Tkinter: Why aren't my widgets expanding when I resize the window? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-03-06 01:58 +0000
Re: Tkinter: Why aren't my widgets expanding when I resize the window? Rick Johnson <rantingrickjohnson@gmail.com> - 2012-03-05 18:20 -0800
Re: Tkinter: Why aren't my widgets expanding when I resize the window? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-03-06 02:33 +0000
Re: Tkinter: Why aren't my widgets expanding when I resize the window? Rick Johnson <rantingrickjohnson@gmail.com> - 2012-03-05 18:56 -0800
Re: Tkinter: Why aren't my widgets expanding when I resize the window? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-03-06 03:09 +0000
Re: Tkinter: Why aren't my widgets expanding when I resize the window? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-03-05 12:25 -0500
| From | John Salerno <johnjsal@gmail.com> |
|---|---|
| Date | 2012-03-04 23:12 -0800 |
| Subject | Tkinter: Why aren't my widgets expanding when I resize the window? |
| Message-ID | <32271364.3080.1330931558529.JavaMail.geo-discussion-forums@ynjd19> |
I can't seem to wrap my head around all the necessary arguments for making a widget expand when a window is resized. I've been following along with a tutorial and I feel like I'm doing everything it said, but I must be missing something. Here's what I have. What I expect is that when I resize the main window, I should be able to see the AppFrame's border stretch out, but it remains in the original position.
Is there something wrong with the sticky argument, maybe? The tutorial I'm reading says they can be strings, but it also uses what appears to be a tuple of constants like this: sticky=(N, S, E, W) -- but that didn't work either.
import tkinter as tk
import tkinter.ttk as ttk
class AppFrame(ttk.Frame):
def __init__(self, parent, **kwargs):
super().__init__(parent, **kwargs)
self.grid(row=0, column=0, sticky='nsew')
self.columnconfigure(0, weight=1)
self.rowconfigure(0, weight=1)
self.create_widgets()
def create_widgets(self):
entry = ttk.Entry(self)
entry.grid(row=0, column=1, sticky='nsew')
#entry.columnconfigure(0, weight=1)
#entry.rowconfigure(0, weight=1)
label = ttk.Label(self, text='Name:')
label.grid(row=0, column=0, sticky='nsew')
root = tk.Tk()
root.title('Test Application')
frame = AppFrame(root, borderwidth=15, relief='sunken')
root.mainloop()
[toc] | [next] | [standalone]
| From | Rick Johnson <rantingrickjohnson@gmail.com> |
|---|---|
| Date | 2012-03-05 05:09 -0800 |
| Message-ID | <bf09a908-2b08-42cb-b856-7be04b1ef7b1@r1g2000yqk.googlegroups.com> |
| In reply to | #21223 |
On Mar 5, 1:12 am, John Salerno <johnj...@gmail.com> wrote:
> I can't seem to wrap my head around all the necessary arguments
> for making a widget expand when a window is resized.
You will need to configure the root columns and rows also because the
configurations DO NOT propagate up the widget hierarchy! Actually, for
this example, I would recommend using the "pack" geometry manager on
the frame. Only use grid when you need to use grid. Never use any
functionality superfluously! Also, you should explicitly pack the
frame from OUTSIDE frame.__init__()!
## START CODE ##
import tkinter as tk
import tkinter.ttk as ttk
from tkinter.constants import BOTH, YES
class AppFrame(ttk.Frame):
def __init__(self, parent, **kwargs):
super().__init__(parent, **kwargs)
self._create_widgets()
def _create_widgets(self):
entry = ttk.Entry(self)
entry.grid(row=0, column=1, sticky='nsew')
label = ttk.Label(self, text='Name:')
label.grid(row=0, column=0, sticky='nsew')
root = tk.Tk()
root.title('Test Application')
frame = AppFrame(root, borderwidth=15, relief='sunken')
frame.pack(fill=BOTH, expand=YES)
root.mainloop()
## END CODE ##
> Is there something wrong with the sticky argument, maybe? The
> tutorial I'm reading says they can be strings, but it also uses what
> appears to be a tuple of constants like this: sticky=(N, S, E, W) --
> but that didn't work either.
I always use either:
sticky='nswe'
sticky=N+S+W+E
[toc] | [prev] | [next] | [standalone]
| From | John Salerno <johnjsal@gmail.com> |
|---|---|
| Date | 2012-03-05 09:31 -0800 |
| Message-ID | <19872402.359.1330968669581.JavaMail.geo-discussion-forums@ynnj12> |
| In reply to | #21229 |
> You will need to configure the root columns and rows also because the > configurations DO NOT propagate up the widget hierarchy! Actually, for > this example, I would recommend using the "pack" geometry manager on > the frame. Only use grid when you need to use grid. Never use any > functionality superfluously! Also, you should explicitly pack the > frame from OUTSIDE frame.__init__()! Ok, so use pack when putting the frame into the root, since that's all that goes into the root directly. But just out of curiosity, what did I do wrong with using grid? How would it work with grid? > from tkinter.constants import BOTH, YES > I always use either: > > sticky='nswe' > sticky=N+S+W+E This is something I'm not too thrilled with. I don't like importing things piecemeal. I suppose I could do: import tkinter.constants as tkc (or something like that) and qualify each constant. Seems like more work, but it just seems better than having to manage each constant that I need in the import list. Also, N+S+E+W and (N, S, E, W) don't seem to work unless qualified, so that's four more constants I'd have to explicitly import. And (tk.N, tk.S, tk.E, tk.W) is just horrible to look at.
[toc] | [prev] | [next] | [standalone]
| From | Rick Johnson <rantingrickjohnson@gmail.com> |
|---|---|
| Date | 2012-03-05 11:03 -0800 |
| Message-ID | <01a0499e-616f-4395-95d2-b6e54e03bc79@i5g2000yqo.googlegroups.com> |
| In reply to | #21235 |
On Mar 5, 11:31 am, John Salerno <johnj...@gmail.com> wrote:
> Ok, so use pack when putting the frame into the root, since that's
> all that goes into the root directly. But just out of curiosity,
> what did I do wrong with using grid? How would it work with grid?
If you read my post carefully, i said: "You need to use
columnconfigure and rowconfigure on ROOT!". Here is the solution;
although, not the correct code you should use because pack is perfect
for this:
## START CODE ##
import tkinter as tk
import tkinter.ttk as ttk
class AppFrame(ttk.Frame):
def __init__(self, parent, **kwargs):
super().__init__(parent, **kwargs)
self.create_widgets()
def create_widgets(self):
entry = ttk.Entry(self)
entry.grid(row=0, column=1, sticky='nsew')
label = ttk.Label(self, text='Name:')
label.grid(row=0, column=0, sticky='nsew')
root = tk.Tk()
root.title('Test Application')
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)
frame = AppFrame(root, borderwidth=15, relief='sunken')
frame.grid(row=0, column=0, sticky='nsew')
root.mainloop()
## END CODE ##
> I don't like importing things piecemeal. I suppose I could do:
So you prefer to pollute? How bout we just auto import the whole
Python stdlib so you can save a few keystrokes?
> import tkinter.constants as tkc (or something like that)
>
> and qualify each constant. Seems like more work, but it just seems
> better than having to manage each constant that I need in the import
> list.
Then do "from tkinter.constants import *". I have no complaints
against import all the constants during testing/building, however, you
should be a professional and import only the constants you are going
to use.
> Also, N+S+E+W and (N, S, E, W) don't seem to work unless qualified,
Of course not, you never imported them! How could that code possibly
work?
> so that's four more constants I'd have to explicitly import. And
> (tk.N, tk.S, tk.E, tk.W) is just horrible to look at.
Wah!
Stop whining and act like a professional! You complain about
qualifying constants but you happily type "self" until your fingers
bleed without even a whimper???
Look, either import ONLY the constants you need, or qualify each
constant with a module name/variable; that is the choices available to
a professional. Or, just be lazy and pollute your namespace.
FYI: Lazy coders get what they deserve in the end.
[toc] | [prev] | [next] | [standalone]
| From | John Salerno <johnjsal@gmail.com> |
|---|---|
| Date | 2012-03-05 14:07 -0800 |
| Message-ID | <20757474.2202.1330985225312.JavaMail.geo-discussion-forums@ynlt17> |
| In reply to | #21236 |
> > I don't like importing things piecemeal. I suppose I could do: > > So you prefer to pollute? How bout we just auto import the whole > Python stdlib so you can save a few keystrokes? > > so that's four more constants I'd have to explicitly import. And > > (tk.N, tk.S, tk.E, tk.W) is just horrible to look at. > > Wah! > > Stop whining and act like a professional! You complain about > qualifying constants but you happily type "self" until your fingers > bleed without even a whimper??? > > Look, either import ONLY the constants you need, or qualify each > constant with a module name/variable; that is the choices available to > a professional. Or, just be lazy and pollute your namespace. > > FYI: Lazy coders get what they deserve in the end. How exactly am I being lazy and polluting the namespace? I never said I wanted to use the "*" import method, if that's what you are (wrongly) assuming. I said it seems cleaner and, to me, LESS lazy to import the whole module as "import tkinter.constants as tkc" and qualify everything. It's certainly more explicit than importing constants on an as-needed basis, having an ever-increasing list of constants, and referring to them unqualified in the code. Yes, I complain that tk.N, tk.S, etc. is ugly to look at, but I'm saying it seems like a better way than using them unqualified, unless maybe there is yet another, better way. As far as using "self" all the time, how do you know I never "whimpered" about it? The first time I learned about it I DIDN'T like it, because it seemed like a lot of unnecessary typing, but eventually I came to accept it because 1) you HAVE to do it, unlike the various options for referring to these constants, and 2) I began to like the explicitness of qualifying everything with "self." You are very helpful, but you sure like to throw around the term "lazy" a little too unabashedly. I never said I wanted to import with "*", which you seem to think I want to do. I LIKE qualifying things, which is the reason I didn't care so much for your method of importing the constants by name.
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2012-03-06 01:10 +0000 |
| Message-ID | <4f55641a$0$29989$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #21240 |
On Mon, 05 Mar 2012 14:07:05 -0800, John Salerno quoted: >> Wah! >> >> Stop whining and act like a professional! You complain about qualifying >> constants but you happily type "self" until your fingers bleed without >> even a whimper??? John, it is polite to leave attributions in place when you quote somebody. I don't know who you are quoting above, but given the obnoxious tone and the fact that this is about Tkinter, I'm guessing it is RantingRick, a.k.a. Rick Johnson. Rick is a notorious troll, and you'll probably save yourself a lot of grief if you pay no attention to him. It's not so much that his advice is *always* bad, but that you'll spend so many hours sifting through the piles of bad advice, unprofessional language, and annoying self- aggrandisement for the occasional nugget of gold that it just isn't worth it. Which is a pity, because I gather that Rick actually does know Tkinter well. But dealing with him is like wrestling with a pig: "I learned long ago, never to wrestle with a pig. You get dirty, and besides, the pig likes it." -- George Bernard Shaw -- Steven
[toc] | [prev] | [next] | [standalone]
| From | John Salerno <johnjsal@gmail.com> |
|---|---|
| Date | 2012-03-05 17:53 -0800 |
| Message-ID | <25803773.4638.1330998809513.JavaMail.geo-discussion-forums@vbw15> |
| In reply to | #21244 |
On Monday, March 5, 2012 7:10:50 PM UTC-6, Steven D'Aprano wrote: > On Mon, 05 Mar 2012 14:07:05 -0800, John Salerno quoted: > > >> Wah! > >> > >> Stop whining and act like a professional! You complain about qualifying > >> constants but you happily type "self" until your fingers bleed without > >> even a whimper??? > > John, it is polite to leave attributions in place when you quote > somebody. I don't know who you are quoting above, but given the obnoxious > tone and the fact that this is about Tkinter, I'm guessing it is > RantingRick, a.k.a. Rick Johnson. > > Rick is a notorious troll, and you'll probably save yourself a lot of > grief if you pay no attention to him. It's not so much that his advice is > *always* bad, but that you'll spend so many hours sifting through the > piles of bad advice, unprofessional language, and annoying self- > aggrandisement for the occasional nugget of gold that it just isn't worth > it. > > Which is a pity, because I gather that Rick actually does know Tkinter > well. But dealing with him is like wrestling with a pig: > > "I learned long ago, never to wrestle with a pig. You get dirty, and > besides, the pig likes it." -- George Bernard Shaw > > > -- > Steven Thank you. Sorry about the attribution. That was my fault because I was trying to cite just the relevant bits, and I cut off the header too.
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2012-03-06 01:58 +0000 |
| Message-ID | <mailman.414.1330999129.3037.python-list@python.org> |
| In reply to | #21244 |
On 06/03/2012 01:10, Steven D'Aprano wrote: > Which is a pity, because I gather that Rick actually does know Tkinter > well. +1. Please Rick less of the Dark Side. :) -- Cheers. Mark Lawrence.
[toc] | [prev] | [next] | [standalone]
| From | Rick Johnson <rantingrickjohnson@gmail.com> |
|---|---|
| Date | 2012-03-05 18:20 -0800 |
| Message-ID | <29142434-eeaf-4c94-8d64-f1f2d4cb500e@t15g2000yqi.googlegroups.com> |
| In reply to | #21244 |
On Mar 5, 7:10 pm, Steven D'Aprano <steve +comp.lang.pyt...@pearwood.info> wrote: > John, it is polite to leave attributions in place when you quote > somebody. I don't know who you are quoting above, > [...] > Which is a pity, because I gather that Rick actually does know Tkinter > well. My, my. Between your ad hominem attacks, FUD, wild assumptions, and veiled insults you did manage to get ONE small sentence of truthful content to propagate up; congratulations! Excuse me whist i toss my cookies! > But dealing with him is like wrestling with a pig: And there it is again. We can't admit Rick is correct without insulting him. But Steven, when have you EVER dealt with me on a professional level? When have you EVER offered a helping hand to one of my issues? For example: I can remember asking you to explain the new .format method of Py3000 and you said: "Sorry, too busy!". But you where not too busy to troll-up the list! WHEN have you ever admitted (without insulting me first) that i am in fact an asset to this community? Do you think this community will ever be a homogeneous block? And if so, would that be a good thing? I have an idea: How about YOU stop clinging to some archaic ideal of what YOU *think* this community *should* be, and instead, start opening up your mind to diverse personalities and diverse ideas. Heck, maybe you'll learn something new, "old dog". Remember how much you ranted about diversity in evolution? And now you have the AUDACITY to preach the opposite just to suit your own selfish argument. You are as hollow as a politician Steven. Nothing that you say can be taken seriously because it is just more propaganda and lies. And one more thing, If ANYONE on this list deserves "thespian of the year" award, it is you my friend! Between your comeo appearances as "Devils Advocate", "Sammy the Strawman Stuffer", "Snarky Detractor", and the ever-present "Troll Slayer" (saving damsels in distress from the trolls of c.l.p) -- i'd say you have the nomination won by a landslide!
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2012-03-06 02:33 +0000 |
| Message-ID | <mailman.417.1331001213.3037.python-list@python.org> |
| In reply to | #21250 |
On 06/03/2012 02:20, Rick Johnson wrote: > On Mar 5, 7:10 pm, Steven D'Aprano<steve > +comp.lang.pyt...@pearwood.info> wrote: > >> John, it is polite to leave attributions in place when you quote >> somebody. I don't know who you are quoting above, >> [...] >> Which is a pity, because I gather that Rick actually does know Tkinter >> well. > > My, my. Between your ad hominem attacks, FUD, wild assumptions, and > veiled insults you did manage to get ONE small sentence of truthful > content to propagate up; congratulations! Excuse me whist i toss my > cookies! > >> But dealing with him is like wrestling with a pig: > > And there it is again. We can't admit Rick is correct without > insulting him. > > But Steven, when have you EVER dealt with me on a professional level? > When have you EVER offered a helping hand to one of my issues? For > example: I can remember asking you to explain the new .format method > of Py3000 and you said: "Sorry, too busy!". But you where not too busy > to troll-up the list! WHEN have you ever admitted (without insulting > me first) that i am in fact an asset to this community? Do you think > this community will ever be a homogeneous block? And if so, would that > be a good thing? > > I have an idea: How about YOU stop clinging to some archaic ideal of > what YOU *think* this community *should* be, and instead, start > opening up your mind to diverse personalities and diverse ideas. Heck, > maybe you'll learn something new, "old dog". Remember how much you > ranted about diversity in evolution? And now you have the AUDACITY to > preach the opposite just to suit your own selfish argument. You are as > hollow as a politician Steven. Nothing that you say can be taken > seriously because it is just more propaganda and lies. > > And one more thing, If ANYONE on this list deserves "thespian of the > year" award, it is you my friend! Between your comeo appearances as > "Devils Advocate", "Sammy the Strawman Stuffer", "Snarky Detractor", > and the ever-present "Troll Slayer" (saving damsels in distress from > the trolls of c.l.p) -- i'd say you have the nomination won by a > landslide! > There is no need for this. You (as I've stated in another reply) seem to know what you're talking about WRT tkinter so please stick with the Light rather than the Dark Side. -- Cheers. Mark Lawrence.
[toc] | [prev] | [next] | [standalone]
| From | Rick Johnson <rantingrickjohnson@gmail.com> |
|---|---|
| Date | 2012-03-05 18:56 -0800 |
| Message-ID | <69af9e72-270f-4ba9-a24c-dfc81a965afd@k29g2000yqc.googlegroups.com> |
| In reply to | #21251 |
On Mar 5, 8:33 pm, Mark Lawrence <breamore...@yahoo.co.uk> wrote: > please stick with the > Light rather than the Dark Side. You're correct. I need to ignore these negative distractions. Thanks for re-focusing the conversation.
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2012-03-06 03:09 +0000 |
| Message-ID | <mailman.419.1331003383.3037.python-list@python.org> |
| In reply to | #21254 |
On 06/03/2012 02:56, Rick Johnson wrote: > On Mar 5, 8:33 pm, Mark Lawrence<breamore...@yahoo.co.uk> wrote: >> please stick with the >> Light rather than the Dark Side. > > You're correct. I need to ignore these negative distractions. Thanks > for re-focusing the conversation. No problem, but as I've often stated in the past my normal professional fee applies which is two (2) pints of Ringwood Old Thumper or equivalent should you ever be in my neck of the woods. :) http://www.ringwoodbrewery.co.uk/beers/beer.aspx?bid=3 -- Cheers. Mark Lawrence.
[toc] | [prev] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2012-03-05 12:25 -0500 |
| Message-ID | <mailman.406.1330968317.3037.python-list@python.org> |
| In reply to | #21223 |
On Sun, 4 Mar 2012 23:12:38 -0800 (PST), John Salerno
<johnjsal@gmail.com> declaimed the following in
gmane.comp.python.general:
> Is there something wrong with the sticky argument, maybe? The tutorial I'm reading says they can be strings, but it also uses what appears to be a tuple of constants like this: sticky=(N, S, E, W) -- but that didn't work either.
>
Those are probably "constants" defined in either tkinter or
tkinter.ttk; since you didn't use the 'from module import *' style you
likely would need to qualify the tuple: (tk.N, tk.S, etc.)
{Note: I've only done ONE tkinter application and that was back on
Python 2.3; and no resizing allowed <G>}
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web