Discussion:
[Tkinter-discuss] Facing issue to show the default button Selected on MAC OS - urgent
YMohan
2009-03-28 09:28:47 UTC
Permalink
Hi All,

I am using MAC OS 10.5.1 and Python 2.5.1. I want to show the defalut
selected button in Tk window. I have two buttons OK and CANCEL. I want to
show the by default OK Button selected but I am not able to do the same on
MAC environment. The same code works in Windows. I have tried to set the
background color of button but no success. Please refer the attached images.
First image is MAC window and second one is Window's window.

Can anybody tell me what I am doing wrong in below code or how to set the
default selected button? I have written the following code -

from Tkinter import *

def closeApp():
root.destroy()

def replySUBJECTNAME(root):
print 'Ok clicked'
def SUBJECTNAME(root):
w=root.winfo_screenwidth()
h=root.winfo_screenheight()
root.geometry('220x100+%d+%d' % ((w-220)/2, (h-100)/2))
root.title("SUBJECT NAME")
btn=Button(root, name="okbutton", text="OK", command=(lambda:
replySUBJECTNAME(root)))
btn.configure(bg = "blue", fg = "red")
btn.grid(row="0", column="0", sticky=NW)
btn.bind('<Return>', lambda e:replySUBJECTNAME(root))
btn.focus_set()
Button(root, text="Cancel", command=(lambda: closeApp())).grid(row="0",
column="0", sticky=N)
entry = Entry(root, width = "30", name="entry").grid(row="1",
column="0")
child = root.nametowidget("entry")
child.insert(0, "Subject Name")

root = Tk()
SUBJECTNAME(root)
root.mainloop()

Please let me know what I am doing wrong in above code or if any other
approach?

Thanks in advance.

Yogendra Mohan Loading Image...
Loading Image...
--
View this message in context: http://www.nabble.com/Facing-issue-to-show-the-default-button-Selected-on-MAC-OS----urgent-tp22755049p22755049.html
Sent from the Python - tkinter-discuss mailing list archive at Nabble.com.
Kevin Walzer
2009-03-30 14:01:52 UTC
Permalink
Post by YMohan
Hi All,
I am using MAC OS 10.5.1 and Python 2.5.1. I want to show the defalut
selected button in Tk window. I have two buttons OK and CANCEL. I want to
show the by default OK Button selected but I am not able to do the same on
MAC environment. The same code works in Windows. I have tried to set the
background color of button but no success. Please refer the attached images.
First image is MAC window and second one is Window's window.
Can anybody tell me what I am doing wrong in below code or how to set the
default selected button? I have written the following code -
On the Mac, Tk buttons ignore the -bg and -fg flags.

The way to specify the default button would be something like this:

btn.configure(bg = "blue", fg = "red", default=ACTIVE)

That shows the Mac Tk button with focus/selected state. This should work
on Windows, as well--there's no need to specify -fg and -bg colors to
indicate default status.
--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
Loading...