473,372 Members | 1,101 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,372 software developers and data experts.

Changing font style/size for overall wx.python GUI look

46
Hey guys

I have had a bit of a hunt around on google to try find out how to change the overall default font style/size for a wx.python app - but not had any luck.

Does anyone have any idea if it is possible?

All I really want to do is make the wx.StaticText, wx.CheckBox, wx.TextCtrl & wx.Button fonts smaller in my GUI app

Thanks if anyone can give me some pointers!

Cheers

Adam
Jul 11 '07 #1
4 14004
bartonc
6,596 Expert 4TB
Hey guys

I have had a bit of a hunt around on google to try find out how to change the overall default font style/size for a wx.python app - but not had any luck.

Does anyone have any idea if it is possible?

All I really want to do is make the wx.StaticText, wx.CheckBox, wx.TextCtrl & wx.Button fonts smaller in my GUI app

Thanks if anyone can give me some pointers!

Cheers

Adam
One word: inheritance! Set the font size for a panel and all the widgets on that panel get that font size by default. Same thing with any parent of any widget. Since the app is not a window, nobody inherits attributes from it.

I'm pretty sure, but I'll double check that.
Jul 11 '07 #2
bartonc
6,596 Expert 4TB
One word: inheritance! Set the font size for a panel and all the widgets on that panel get that font size by default. Same thing with any parent of any widget. Since the app is not a window, nobody inherits attributes from it.

I'm pretty sure, but I'll double check that.
wxWindow is the lowes object that I could find that has a font attribute. The most interesting thing that I stumbled across was this:
wxWindow::InheritAttributes
void InheritAttributes()

This function is (or should be, in case of custom controls) called during window creation to intelligently set up the window visual attributes, that is the font and the foreground and background colours.

By "intelligently'' the following is meant: by default, all windows use their own default attributes. However if some of the parents attributes are explicitly (that is, using SetFont and not SetOwnFont) changed and if the corresponding attribute hadn't been explicitly set for this window itself, then this window takes the same value as used by the parent. In addition, if the window overrides ShouldInheritColours to return false, the colours will not be changed no matter what and only the font might.

This rather complicated logic is necessary in order to accommodate the different usage scenarios. The most common one is when all default attributes are used and in this case, nothing should be inherited as in modern GUIs different controls use different fonts (and colours) than their siblings so they can't inherit the same value from the parent. However it was also deemed desirable to allow to simply change the attributes of all children at once by just changing the font or colour of their common parent, hence in this case we do inherit the parents attributes.
Jul 11 '07 #3
ateale
46
Thanks BartonC !
I had a look and tried to use:
font = wx.Font(10, wx.FONTFAMILY_MODERN, wx.NORMAL, wx.BOLD)
wx.Window.SetFont(self, font)

but it doesn't change anything

I don't think i really understand the wx.window and inheritance thing. I read about inheritance in the doc, but I don't understand how to apply it to my script

i just realised I am using wx.Frame not wx.Window - guess this is the reason?

Any ideas?

Thanks!

Adam
Jul 13 '07 #4
bartonc
6,596 Expert 4TB
Thanks BartonC !
I had a look and tried to use:
panel.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))

but it doesn't change anything

I don't think i really understand the wx.window and inheritance thing. I read about inheritance in the doc, but I don't understand how to apply it to my script

Any ideas?

Thanks!

Adam
Yep. When you're sticking down your widgets in a frame, you need to watch who the parent is. I'll use a subclass of dialog as an example:
Expand|Select|Wrap|Line Numbers
  1. class SegmentDialog(wx.Dialog):   # The parent of widgets that get self as their parent
  2.     def _init_ctrls(self, prnt):
  3.         # generated method, don't edit
  4.         wx.Dialog.__init__(self, id=wxID_SEGMENTDIALOG, name='SegmentDialog', parent=prnt,
  5.                 pos=wx.Point(8, 8), size=wx.Size(1008, 724), style=wx.DEFAULT_DIALOG_STYLE,
  6.                 title='Station Capture - HETAP Pro 2.0')
  7.         self.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.NORMAL, False,'MS Shell Dlg 2'))
  8. # the panel would get that font, but gets its own, instead.
  9.  
  10.         self.panel1 = wx.Panel(id=wxID_SEGMENTDIALOGPANEL1, name='panel1', parent=self,   # Here is the panel's parent #
  11.                 pos=wx.Point(0, 0), size=wx.Size(1008, 696), style=wx.TAB_TRAVERSAL)
  12.         self.panel1.SetBackgroundColour(wx.Colour(232, 232, 232))
  13.         self.panel1.SetToolTipString('')
  14.         self.panel1.SetFont(wx.Font(16, wx.SWISS, wx.NORMAL, wx.BOLD, False,'MS Shell Dlg 2'))
  15. # widgets get the panel as the parent
  16.  
  17.         self.staticLine1 = wx.StaticLine(id=wxID_SEGMENTDIALOGSTATICLINE1, name='staticLine1',
  18.                 parent=self.panel1, pos=wx.Point(16, 185), size=wx.Size(795, 3), style=0)
  19. # and, so, get that font
  20.  
  21.     def __init__(self, parent, dbDialog, publisher):
  22.         self._init_ctrls(parent)
Hope that's clear.
Jul 13 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

131
by: Peter Foti | last post by:
Simple question... which is better to use for defining font sizes and why? px and em seem to be the leading candidates. I know what the general answer is going to be, but I'm hoping to ultimately...
0
by: Paul D. Sullivan | last post by:
I've been trying to find out how to increase the font size in the text entry fields in Invision Power Board 1.3 for a while. The part where you enter your post and do the quick reply and all that...
31
by: Arthur Shapiro | last post by:
I'm the webmaster for a recreational organization. As part of one page of the site, I have an HTML "Calendar at a Glance" of the organization's events for the month. It's a simple table of a...
4
by: tshad | last post by:
I am having trouble with links in my DataGrid. I have Links all over my page set to smaller and they are consistant all over the page in both Mozilla and IE, except for the DataGrid. Here is a...
7
by: Sakharam Phapale | last post by:
Hi All, How to preserve the old font properties while changing new one? I posted same question 2 months back, but I had very small time then. eg. "Shopping for" is a text in RichTextBox and...
15
by: phillip.s.powell | last post by:
<style> div div table tr td a.navbar, div div table tr td font {display: none;} </style> <div class="navigationbar" style="background-color:Black; position: absolute; left:50%; top:127px;...
30
by: Takehiko Abe | last post by:
I have a <pelement with <ttinside: ;;; <p>A paragraph contains <tt>tt element</tt>.</p> I would like to set the font-size of the TT to the same as the containing <p>. This does not seem to...
18
by: Diogenes | last post by:
Hi All; I, like others, have been frustrated with designing forms that look and flow the same in both IE and Firefox. They simply did not scale the same. I have discovered, to my chagrin,...
4
by: gubbachchi | last post by:
Hi all, Please anybody help me solve this problem. I am stuck up with this from past 2 weeks. I am developing an application where, when the user selects date from javascript datepicker and enters...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.