Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #41559

Re: Python GUI questions

References <4250fe44-c09c-48a8-aca2-51c1a8bc3a48@googlegroups.com> <e745739b-a9bb-49a3-8a06-1b4ae3f4d901@googlegroups.com> <262b7363-f980-4926-bb36-1f795769b359@googlegroups.com>
Date 2013-03-19 22:14 -0400
Subject Re: Python GUI questions
From Jason Swails <jason.swails@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.3541.1363745651.2939.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On Tue, Mar 19, 2013 at 9:25 PM, maiden129 <sengokubasarafever@gmail.com>wrote:

> On Tuesday, March 19, 2013 8:57:42 PM UTC-4, Rick Johnson wrote:
> > On Tuesday, March 19, 2013 2:01:24 PM UTC-5, maiden129 wrote:
> >
> > > Hello,
> >
> > >
> >
> > > I'm using python 3.2.3 and I'm making a program that show
> >
> > > the of occurrences of the character in the string in
> >
> > > Tkinter.
> >
> > >
> >
> > > My questions are:
> >
> > >
> >
> > > How can I make an empty Entry object that will hold a word
> >
> > > that a user will enter?
> >
> >
> >
> > I believe you meant to say: "How can i CREATE an entry field to
> accommodate user input?"
> >
> >
> >
> > Easy.
> >
> >
> >
> > > How to make an empty Entry object that will hold a single
> >
> > > character that the user will enter?
> >
> >
> >
> > Not as easy, but still quite doable. Do you want to filter the input,
> allowing only a single character?
> >
> >
> >
> > > How to A Button object with a text equal to "Count"?
> >
> >
> >
> > Easy-pee-see. Follow this yellow brick road to enlightenment.
> >
> >
> >
> >   http://effbot.org/tkinterbook/tkinter-whats-tkinter.htm
>
> Hello,
>
> Here is my try to answer some of questions:
>
>
> from tkinter import *
>
> class word:
>     def __init__(self,Entry,Character):
>         window = Tk()
>         window.title("Widget")
>
>         top = Tk()
>         L1 = Label(top, text="Enter a string")
>         L1.pack( side = LEFT)
>         E1 = Entry(top, bd =5)
>

This is unlikely to work.  You have overwritten the Entry widget from
tkinter, meaning that E1 will not be an Entry (unless you pass
tkinter.Entry to a word() instance, which seems redundant).

My suggestion is actually to generate classes derived from tkinter widgets
(I often use Frame, since it's quite generic and can act as a container for
any other widget easily).


>         E1.pack(side = RIGHT)
>
>         top.mainloop()
>
>         L2 = Label(bottom, text="Number of single characters")
>         L2.pack( side = LEFT)
>         E2 = Entry(bottom, bd =5)
>
>         button = Tkinter.Button(bottom, text ="Count", command =
>  countCharacter).pack()
>
>         def countChacater(self):
>             count = word.count(character)
>
> I'm just struggling with only how to create an object that will hold a
> single character that the user will enter.
>

This is tricky.  The approach I would take is to generate an entry widget
and then bind all key-press events in that widget to a method that checks
how long the input string is.  If it is longer than a single character,
reject the new letter and optionally raise an alert (using, e.g.,
tkMessageBox.showwarning).

If you want the count on the button to be updated continuously, you'll need
to update that counter every time either the input string or character is
changed.

Good luck,
Jason

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Python GUI  questions maiden129 <sengokubasarafever@gmail.com> - 2013-03-19 12:01 -0700
  Re: Python GUI questions Chris Angelico <rosuav@gmail.com> - 2013-03-20 08:39 +1100
    Re: Python GUI questions maiden129 <sengokubasarafever@gmail.com> - 2013-03-19 15:50 -0700
    Re: Python GUI questions maiden129 <sengokubasarafever@gmail.com> - 2013-03-19 15:50 -0700
  Re: Python GUI  questions Rick Johnson <rantingrickjohnson@gmail.com> - 2013-03-19 17:57 -0700
    Re: Python GUI  questions maiden129 <sengokubasarafever@gmail.com> - 2013-03-19 18:25 -0700
      Re: Python GUI questions Ranting Rick <rantingrickjohnson@gmail.com> - 2013-03-19 19:16 -0700
        Re: Python GUI questions maiden129 <sengokubasarafever@gmail.com> - 2013-03-19 19:36 -0700
          Re: Python GUI questions Rick Johnson <rantingrickjohnson@gmail.com> - 2013-03-19 20:06 -0700
        Re: Python GUI questions Terry Reedy <tjreedy@udel.edu> - 2013-03-19 23:21 -0400
          Re: Python GUI questions Rick Johnson <rantingrickjohnson@gmail.com> - 2013-03-20 10:37 -0700
      Re: Python GUI questions Jason Swails <jason.swails@gmail.com> - 2013-03-19 22:14 -0400
  Re: Python GUI  questions Jan Riechers <janpeterr@freenet.de> - 2013-03-31 16:33 +0300

csiph-web