Tkinter buttons
Richard Chamberlain
richard_chamberlain at ntlworld.com
Sat Aug 5 09:19:07 EDT 2000
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
More information about the Python-list
mailing list