By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,611 Members | 1,633 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,611 IT Pros & Developers. It's quick & easy.

Setting default option values for Tkinter widgets

P: n/a
There are certain options for Tkinter widgets that have default values
that I don't much care for (borderwidth, font come to mind) and
continuously change when I'm building interfaces. With a bit of
tweaking I have been able to give the widgets a look that rivals the
best of them. However, I get tired of doing this when I'm writing code
and would like a way that I could universally change them on my system.
I have tried to find where in the class files (Tkinter.py) that I can
change these and haven't been able to find them. Are there certain
lines in certain files/modules/classes that I can change the values for
these things like font, border, etc.?

Thanks,

Harlin

Jul 18 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
On 3 Mar 2005 03:02:48 -0800, Harlin Seritt <ha**********@yahoo.com> wrote:
There are certain options for Tkinter widgets that have default values
that I don't much care for (borderwidth, font come to mind) and
continuously change when I'm building interfaces. With a bit of
tweaking I have been able to give the widgets a look that rivals the
best of them. However, I get tired of doing this when I'm writing code
and would like a way that I could universally change them on my system.
I have tried to find where in the class files (Tkinter.py) that I can
change these and haven't been able to find them. Are there certain
lines in certain files/modules/classes that I can change the values for
these things like font, border, etc.?


tk allows to write your preffered options to an option file and to load it via the method option_readfile in your application.

For an example on how the options can be set, see:
http://mini.net/tcl/10424
The file should contain the arguments passed to "option add" commands.

For a reference on what options are available and how to specify them in an option file, see the tk manual pages here:
http://www.tcl.tk/man/tcl8.4/TkCmd/contents.htm
The name for the widget is usually the name of the corresponding Tkinter class; the name for the option is the second name found in the standard and widget-specific options sections in the man pages (named "Database name" in the section text). So for example, if you want to set the default select color for checkbuttons, you'll put in your option file a line:

*Checkbutton.selectColor: blue

HTH
--
python -c 'print "".join([chr(154 - ord(c)) for c in "U(17zX(%,5.z^5(17l8(%,5.Z*(93-965$l7+-"])'
Jul 18 '05 #2

P: n/a
Eric, your tagline doesn't parse correctly on my Python 2.4 shell.

Jul 18 '05 #3

P: n/a
st***************@gmail.com wrote:
Eric, your tagline doesn't parse correctly on my Python 2.4 shell.

So, are you using Windows?

sholden@bigboy /c/Python24/Lib/site-packages
$ python -c 'print "".join([chr(154 - ord(c)) for c in
"U(17zX(%,5.z5(17l8(%,5.Z*(93-965$l7+-"])'
Eric Brunel er*********@pragmadev.com

regards
Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005 http://www.pycon.org/
Steve Holden http://www.holdenweb.com/
Jul 18 '05 #4

P: n/a
Steve Holden wrote:
st***************@gmail.com wrote:
Eric, your tagline doesn't parse correctly on my Python 2.4 shell.

So, are you using Windows?


If you interchange single and double quotes it works on Windows too
python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.z^5(17l8(%,5.Z*(93-965$l7+-'])"

Kent
Jul 18 '05 #5

P: n/a
yep, that works better under Windows. Pretty obscure use of Python,
though! :-)

S

Jul 18 '05 #6

P: n/a
I have
listA=[1,2,3,4,5,4,3,4,3,2,1]
and I want a list of only the unique members.

This seems inefficient, but works fine over my small sample lists:
listA=[a for a in set(listA)]

Is there a more efficient approach for cases where listA is large?


Eric Pederson
:::::::::::::::::::::::::::::::::::
domainNot="@something.com"
domainIs=domainNot.replace("s","z")
ePrefix="".join([chr(ord(x)+1) for x in "do"])
mailMeAt=ePrefix+domainIs
:::::::::::::::::::::::::::::::::::

Jul 18 '05 #7

P: n/a
Eric Pederson wrote:
I have
listA=[1,2,3,4,5,4,3,4,3,2,1]
and I want a list of only the unique members.

This seems inefficient, but works fine over my small sample lists:
listA=[a for a in set(listA)]

Is there a more efficient approach for cases where listA is large?


No. But I doubt that that is what you actually want, as listA will lose its
order afterwards. Typically, something like that gets written like this:

inserted = set()
res = []
for e in listA:
if not e in inserted:
res.append(e)
inserted.add(e)
listA = res

Or, with a little helperfunction:

inserted = set()
def foo(e):
inserted.add(e)
return e
listA = [foo(e) for e in listA if not e in inserted]

But ist's not really much better.

--
Regards,

Diez B. Roggisch
Jul 18 '05 #8

P: n/a
Eric Pederson wrote:
I have

listA=[1,2,3,4,5,4,3,4,3,2,1]

and I want a list of only the unique members.

This seems inefficient, but works fine over my small sample lists:

listA=[a for a in set(listA)]
Is there a more efficient approach for cases where listA is large?

no. Even though the code can be a little simpler:

listA = list(Set(listA))

You don't even need to convert it to a list. You can just iterate over
the set.
la = [1,2,3,4,3,2,3,4,5]
from sets import Set
sa = Set(la)
for itm in sa:

.... print itm
1
2
3
4
5

--

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science
Jul 18 '05 #9

P: n/a
"Diez B. Roggisch" <de*********@web.de> wrote:
inserted = set()
res = []
for e in listA:
if not e in inserted:
res.append(e)
inserted.add(e)
listA = res


I'm going to go off on a tangent here and put in a plea for better variable
naming. I'm looking at the above code, and can't figure out what "res" is
supposed to be. Is it short for "rest", as in "the rest of the items"?
Residual? Result? Restore? Any of these seems plausable. Not knowing
which makes it much harder to understand what the code does. When you say
"res.append(e)", are you building up the result that you're going to
return, or are you building up a list of elements that got eliminated (i.e.
residual) because they are duplicates?

Yes, I did eventually figure it out. It didn't even take that long, but
this is a trivial little piece of code; it shouldn't have taken any time at
all to figure it out. All you saved by using "res" instead of "result" was
9 keystrokes ("ult", in three places), but it cost every one of your
readers extra brainpower to figure out what you meant. To quote one of
Aahz's better signatures, "Typing is cheap. Thinking is expensive." :-)
Jul 18 '05 #10

P: n/a
> I'm going to go off on a tangent here and put in a plea for better
variable
naming. I'm looking at the above code, and can't figure out what "res" is
supposed to be. Is it short for "rest", as in "the rest of the items"?
Residual? Result? Restore? Any of these seems plausable. Not knowing
which makes it much harder to understand what the code does. When you say
"res.append(e)", are you building up the result that you're going to
return, or are you building up a list of elements that got eliminated
(i.e. residual) because they are duplicates?

Yes, I did eventually figure it out. It didn't even take that long, but
this is a trivial little piece of code; it shouldn't have taken any time
at
all to figure it out. All you saved by using "res" instead of "result"
was 9 keystrokes ("ult", in three places), but it cost every one of your
readers extra brainpower to figure out what you meant. To quote one of
Aahz's better signatures, "Typing is cheap. Thinking is expensive." :-)


I usually use much more telling variable names - from the source I just
wrote a minute ago:

self.selection_color_map = {}
self.selection_color = (255,255,0)
self.assigned_color_map = {}
self.default_color = (0,0,0)
self.known_names = sets.Set()

As you can see - no desire to shorten names. But "res" for result is as
hardwired to me as i,j,k for iterating numbers. So bear with me on this
case.

--
Regards,

Diez B. Roggisch
Jul 18 '05 #11

P: n/a
Max M wrote:
Eric Pederson wrote:
listA = list(Set(listA))

As of 2.4, set is a built-in type (2.3 had Set in module sets).
Another 2.4-ism is "sorted", which might very well be the way you
want to turn the set into a list:

listA = sorted(set(listA))

for this particular use, you can define sorted in 2.3 as:

def sorted(iterable):
result = list(iterable)
result.sort()
return result

The full sorted functionality can be (and has been) defined in 2.3,
but just using 2.4 would be a better bet.

--Scott David Daniels
Sc***********@Acm.Org
Jul 18 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.