Tkinter buttons

Janos Blazi jblazi at vipsurf.de
Sat Aug 5 20:19:47 EDT 2000


Richard Chamberlain <richard_chamberlain at ntlworld.com> schrieb in im
Newsbeitrag: 398C144B.E1AF1C5F at ntlworld.com...
> Janos Blazi wrote:
> >
> > I'd like to have a button with the following properties:
> >
> > (1) When I push the button, it remains pushed
> > (2)  When I push a button that was pushed it is 'normal' again
> >
> > How to do that?
> >
> > Janos Blazi
> >
> > -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> > http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
> > -----==  Over 80,000 Newsgroups - 16 Different Servers! =-----
>
>
> Hello Janos,
>
> There are two ways to do this (well probably more than two ways :) )
>
> from Tkinter import *
> root=Tk()
> myVar=IntVar()
> checkbutton=Checkbutton(root,text="My
> Button",indicatoron=0,varible=myVar)
> checkbutton.pack()
> def printme(event):
> print myVar.get()
> button.bind('<Button>',printme)
> root.mainloop()
>
> This way uses a Checkbutton (you could also use a Radiobutton) and the
> indicatoron option which makes it look like a button essentially.
>
> The other way:
>
> from Tkinter import *
> root=Tk()
> button=Button(root,text="My Button")
> button.pack()
> def changeme(event):
> if button.cget('relief')==SUNKEN:
> button.config(relief=RAISED)
> else:
> button.config(relief=SUNKEN)
> button.bind('<Button>',changeme)
> root.mainloop()
>
> Which just captures a button event and changes the relief of the button
> accordingly
>
> Richard

Very interesting and exactly what I was looking for. I missed the configure
method. So Thx.
J.B.




-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----



More information about the Python-list mailing list