473,322 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Setting default option values for Tkinter widgets

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
11 2055
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
Eric, your tagline doesn't parse correctly on my Python 2.4 shell.

Jul 18 '05 #3
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
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
yep, that works better under Windows. Pretty obscure use of Python,
though! :-)

S

Jul 18 '05 #6
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
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
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
"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
> 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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: srijit | last post by:
Hello, Any idea - why the following code crashes on my Win 98 machine with Python 2.3? Everytime I run this code, I have to reboot my machine. I also have Win32all-157 installed. from Tkinter...
3
by: rick.lawson | last post by:
I, like a lot of developers, have collected a homegrown set of widgets for Tkinter. Any thoughts on a central repository for Tkinter widgets or widget extensions? Stuff that's not in Tkinter or...
2
by: Adonis | last post by:
I am creating some widgets by inheriting from Tkinter.Frame and populating the frame with whatever the widget will be then creating certain attributes/methods to be accessed later. My question is,...
25
by: BJörn Lindqvist | last post by:
See: http://www.wxpython.org/quotes.php. especially: "wxPython is the best and most mature cross-platform GUI toolkit, given a number of constraints. The only reason wxPython isn't the standard...
3
by: Matt Hammond | last post by:
Here's a strange one in Tkinter that has me stumped: (I'm running python 2.4 on Suse Linux 9.3 64bit) I'm trying to make a set of Entry widgets with Label widgets to the left of each one, using...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
32
by: Kevin Walzer | last post by:
I'm a Tcl/Tk developer who has been working, slowly, at learning Python, in part because Python has better support for certain kinds of applications that I want to develop than Tcl/Tk does....
0
by: Unnamed One | last post by:
First question - is it possible to set font to default OS font for window text? It would be preferable, while on my Windows XP system Tkinter sets small Helvetica-style font by default. ...
3
by: J-Burns | last post by:
Hello. Im a bit new to using Tkinter and im not a real pro in programming itself... :P. Need some help here. Problem 1: How do I make something appear on 2 separate windows using Tkinter? By...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.