Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news1.tnib.de!feed.news.tnib.de!news.tnib.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'reject': 0.05; 'character,': 0.07; 'e.g.,': 0.07; 'tkinter': 0.07; 'python': 0.09; 'derived': 0.09; 'input,': 0.09; 'occurrences': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'bind': 0.16; 'frame,': 0.16; 'luck,': 0.16; 'optionally': 0.16; 'subject:GUI': 0.16; 'subject:questions': 0.16; 'tk()': 0.16; 'tkinter.': 0.16; '\xa0you': 0.16; 'string': 0.17; 'wrote:': 0.17; 'instance,': 0.17; 'widget': 0.17; 'input': 0.18; 'are:': 0.20; 'email addr:gmail.com>': 0.20; 'skip:= 10': 0.20; 'import': 0.21; 'meant': 0.21; 'accommodate': 0.22; 'questions:': 0.22; '\xa0if': 0.22; 'cc:2**0': 0.23; 'work.': 0.23; '>': 0.23; 'seems': 0.23; 'raise': 0.24; 'cc:no real name:2**0': 0.24; 'command': 0.24; 'pass': 0.25; 'cc:addr:python.org': 0.25; 'header :In-Reply-To:1': 0.25; 'message-id:@mail.gmail.com': 0.27; '(unless': 0.29; 'changed.': 0.29; 'container': 0.29; 'unlikely': 0.29; 'character': 0.29; 'skip:& 10': 0.29; 'class': 0.29; "i'm": 0.29; 'classes': 0.30; 'checks': 0.30; 'window': 0.30; 'button': 0.30; 'johnson': 0.32; 'suggestion': 0.32; 'skip:_ 30': 0.32; 'equal': 0.33; 'entry': 0.33; 'received:google.com': 0.34; 'text': 0.34; 'updated': 0.34; 'filter': 0.35; 'generic': 0.35; 'jason': 0.35; 'pm,': 0.35; 'but': 0.36; 'url:org': 0.36; 'method': 0.36; 'quite': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'some': 0.38; 'hello,': 0.39; 'skip:w 30': 0.61; 'side': 0.61; "you'll": 0.62; 'is.': 0.62; 'road': 0.63; 'show': 0.63; 'making': 0.64; 'here': 0.65; 'believe': 0.69; 'url:htm': 0.71; '2013': 0.84; 'brick': 0.84; 'say:': 0.84; 'yellow': 0.84; '"how': 0.91; 'rick': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=CWxpMqrTF1vg1IOOE29R+6PlxcL3n4YPNDPqVYtbW1U=; b=xXLXArcYPtTTRQiy0737bVD2UfAJ5987pfwytvWNSpxWq5Rbb5CfsF1zm6W3bzna7p lsKhDnRO2kLqkZgmg/pWispI4vKi48eYmJlXWR3+OIe2kBNRJ8tiOl80TlVgOyL5BRn3 q7XeSWF4WpOKtfD4Gm+RGx7lYx5yrd2knInlBxD7TYzmyldGrMpzby2pxj/4CWsJQypx 8Zk0BdWR1Cv/Ygm8DzSN40VqkrDb6hHOnB4Sh2P8qJ4XVc/l817u3/MiPjL0gEWFABeu 3sRHC3xwI6oyKzAdPJrji8kiWzHPnVtG+eSHMsXw07LsFjaaQsdgv89+tcK+yzveGvOf alfw== MIME-Version: 1.0 X-Received: by 10.50.190.233 with SMTP id gt9mr3020345igc.80.1363745648066; Tue, 19 Mar 2013 19:14:08 -0700 (PDT) In-Reply-To: <262b7363-f980-4926-bb36-1f795769b359@googlegroups.com> References: <4250fe44-c09c-48a8-aca2-51c1a8bc3a48@googlegroups.com> <262b7363-f980-4926-bb36-1f795769b359@googlegroups.com> Date: Tue, 19 Mar 2013 22:14:07 -0400 Subject: Re: Python GUI questions From: Jason Swails To: maiden129 Content-Type: multipart/alternative; boundary=14dae9341177eacb6804d851c605 Cc: python-list@python.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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 240 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1363745651 news.xs4all.nl 6966 [2001:888:2000:d::a6]:41041 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:41559 --14dae9341177eacb6804d851c605 Content-Type: text/plain; charset=ISO-8859-1 On Tue, Mar 19, 2013 at 9:25 PM, maiden129 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 --14dae9341177eacb6804d851c605 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

On Tue, M= ar 19, 2013 at 9:25 PM, maiden129 <sengokubasarafever@gmail.com= > wrote:
On T= uesday, 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 a= ccommodate 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.
>
>
>
> =A0 http://effbot.org/tkinterbook/tkinter-whats-tkinter.htm=

Hello,

Here is my try to answer some of questions:


from tkinter import *

class word:
=A0 =A0 def __init__(self,Entry,Character):
=A0 =A0 =A0 =A0 window =3D Tk()
=A0 =A0 =A0 =A0 window.title("Widget")

=A0 =A0 =A0 =A0 top =3D Tk()
=A0 =A0 =A0 =A0 L1 =3D Label(top, text=3D"Enter a string")
=A0 =A0 =A0 =A0 L1.pack( side =3D LEFT)
=A0 =A0 =A0 =A0 E1 =3D Entry(top, bd =3D5)

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

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


=A0 =A0 =A0 =A0 E1.pack(side =3D RIGHT)

=A0 =A0 =A0 =A0 top.mainloop()

=A0 =A0 =A0 =A0 L2 =3D Label(bottom, text=3D"Number of single characte= rs")
=A0 =A0 =A0 =A0 L2.pack( side =3D LEFT)
=A0 =A0 =A0 =A0 E2 =3D Entry(bottom, bd =3D5)

=A0 =A0 =A0 =A0 button =3D Tkinter.Button(bottom, text =3D"Count"= , command =3D =A0countCharacter).pack()

=A0 =A0 =A0 =A0 def countChacater(self):
=A0 =A0 =A0 =A0 =A0 =A0 count =3D 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.

<= div>This is tricky. =A0The approach I would take is to generate an entry wi= dget and then bind all key-press events in that widget to a method that che= cks how long the input string is. =A0If it is longer than a single characte= r, reject the new letter and optionally raise an alert (using, e.g., tkMess= ageBox.showwarning).

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

Good luck,
Jason
--14dae9341177eacb6804d851c605--