Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #75576
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'definitions': 0.07; 'tkinter': 0.07; 'subject:help': 0.08; 'buttons': 0.09; 'grid': 0.09; 'mess': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'variable,': 0.09; 'def': 0.12; 'jan': 0.12; 'wrote': 0.14; '0),': 0.16; '1),': 0.16; '2),': 0.16; 'buttons,': 0.16; 'cmd': 0.16; 'expression,': 0.16; 'lambda': 0.16; 'loop.': 0.16; 'pressing': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'subject:Tkinter': 0.16; 'tk()': 0.16; 'do,': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'app': 0.19; 'import': 0.22; 'separate': 0.22; 'header:User-Agent:1': 0.23; 'mind.': 0.24; 'sort': 0.25; 'gets': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'function': 0.29; 'besides': 0.30; 'label': 0.30; 'code': 0.31; "skip:' 10": 0.31; 'skip:# 10': 0.33; 'screen': 0.34; 'but': 0.35; 'there': 0.35; 'next': 0.36; 'entry': 0.36; 'should': 0.36; 'half': 0.37; 'button': 0.38; 'initially': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'does': 0.39; 'received:71': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'above,': 0.60; 'skip:t 30': 0.61; 'box,': 0.64; 'more': 0.64; 'total': 0.65; 'modify.': 0.84; 'received:fios.verizon.net': 0.84; 'boxes': 0.91; 'thing,': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Terry Reedy <tjreedy@udel.edu> |
| Subject | Re: Tkinter grid autosize help |
| Date | Sat, 02 Aug 2014 23:22:29 -0400 |
| References | <60f53f24-7ce7-48e5-9fed-7d9ac8841b7f@googlegroups.com> <bfd8ce20-b31f-4b32-a286-5efece366b73@googlegroups.com> <lrk62h$nb0$1@ger.gmane.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | pool-71-175-90-87.phlapa.fios.verizon.net |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 |
| In-Reply-To | <lrk62h$nb0$1@ger.gmane.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.12568.1407036172.18130.python-list@python.org> (permalink) |
| Lines | 71 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1407036172 news.xs4all.nl 2853 [2001:888:2000:d::a6]:59107 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:75576 |
Show key headers only | View raw
On 8/2/2014 10:16 PM, Terry Reedy wrote:
> On 8/2/2014 6:53 PM, Nicholas Cannon wrote:
>> The only way i can make the buttons look neat and then when i keep
>> pressing one the label gets larger and then half the buttons
>> move out of the screen
With my code below, I tried entering a 20 digit number and the button
boxes separate horizontally. This is not exactly what you describe, but
it does mess up the initially neat display.
>> is there a way i can stop the grid from expanding?
One thing I might do, besides using an entry box, it to grid the buttons
in a separate frame. I wrote the code below, with the header_rows
variable, with that in mind.
> This sort of repetitious code is crying for a loop. For one thing, if
> you want to change the buttons, there should only be one Button call to
> modify. Since I am still learning to write tkinter myself, I wrote the
> following, which I suspect does what you wanted and a bit more.
>
> from tkinter import *
>
> main = Tk()
> main.title('Calculator')
> main.geometry('300x350')
> #main.resizable() # does nothing
>
> app = Frame(main)
> app.grid()
>
> total = IntVar()
> total.set(0)
> entry = StringVar()
> entry.set('')
>
> Label(app, text='Total').grid(row=0, column=0)
> Label(app, textvariable=total).grid(row=0, column=1, columnspan=3)
> Label(app, text='Entry').grid(row=1, column=0)
> Label(app, textvariable=entry).grid(row=1, column=1, columnspan=3)
>
> def append(digit):
> entry.set(entry.get() + digit)
>
> def add():
> total.set(total.get() + int(entry.get()))
> entry.set('')
> def sub():
> total.set(total.get() - int(entry.get()))
> entry.set('')
>
> header_rows = 2
> for num, r, c in (
> ('7', 0, 0), ('8', 0, 1), ('9', 0, 2),
> ('4', 1, 0), ('5', 1, 1), ('6', 1, 2),
> ('1', 2, 0), ('2', 2, 1), ('3', 2, 2),
> ('0', 3, 0), ('+', 3, 1), ('-', 3, 2),):
> cmd = {'+':add, '-':sub}.get(num, lambda num=num: append(num))
> b = Button(app, text=num, command=cmd, width=5)
> b.grid(row=header_rows+r, column=c)
>
> main.mainloop()
With regard to your next message: If you do not understand the function
definitions above, including the lambda expression, and the loop, you
should definitely look more at the tutorial.
--
Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Tkinter grid autosize help Nicholas Cannon <nicholascannon1@gmail.com> - 2014-08-02 07:38 -0700
Re: Tkinter grid autosize help MRAB <python@mrabarnett.plus.com> - 2014-08-02 16:33 +0100
Re: Tkinter grid autosize help Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-02 17:14 +0100
Re: Tkinter grid autosize help Nicholas Cannon <nicholascannon1@gmail.com> - 2014-08-02 15:53 -0700
Re: Tkinter grid autosize help Terry Reedy <tjreedy@udel.edu> - 2014-08-02 22:16 -0400
Re: Tkinter grid autosize help Rick Johnson <rantingrickjohnson@gmail.com> - 2014-08-02 19:24 -0700
Re: Tkinter grid autosize help Terry Reedy <tjreedy@udel.edu> - 2014-08-02 23:22 -0400
Re: Tkinter grid autosize help Nicholas Cannon <nicholascannon1@gmail.com> - 2014-08-02 19:36 -0700
csiph-web