473,769 Members | 2,246 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

wxPython layout problem

py
I have the following code:
Expand|Select|Wrap|Line Numbers
  1. class MainFrame(wx.Frame):
  2. def __init__(self, parent, id, title):
  3. wx.Frame.__init__(self, parent, wx.ID_ANY, title,
  4. style=wx.DEFAULT_FRAME_STYLE |wx.NO_FULL_REPAINT_ON_RESIZE)
  5. # build top area
  6. topSizer = self.buildTopPanel()
  7. # build input area
  8. inputSizer = self.buildInputPanel()
  9.  
  10. mainSizer = wx.BoxSizer(wx.VERTICAL)
  11. mainSizer.Add(topSizer, 1, wx.EXPAND | wx.ALL, 5)
  12. mainSizer.Add(inputSizer, 1, wx.EXPAND | wx.ALL, 5)
  13.  
  14. p = wx.Panel(self, wx.ID_ANY)
  15. p.SetSizer(mainSizer)
  16.  
  17. s = wx.BoxSizer(wx.VERTICAL)
  18. s.Add(p, 1, wx.EXPAND)
  19.  
  20. self.SetAutoLayout(True)
  21. self.SetSizer(s)
  22. self.Layout()
  23.  
  24. def buildTopPanel(self):
  25. p = wx.Panel(self, wx.ID_ANY)
  26. self.text = wx.TextCtrl(p, wx.ID_ANY, style=wx.TE_MULTILINE |
  27. wx.SUNKEN_BORDER)
  28. sizer = wx.BoxSizer(wx.HORIZONTAL)
  29. sizer.Add(self.text, 1, wx.EXPAND)
  30. return sizer
  31.  
  32. def buildInputPanel(self):
  33. # the area to enter text
  34. self.text2 = wx.TextCtrl(self, wx.ID_ANY, style=wx.TE_MULTILINE
  35. | wx.SUNKEN_BORDER)
  36.  
  37. # panel to add button to
  38. p = wx.Panel(self, wx.ID_ANY)
  39. self.buttonClick = wx.Button(p, wx.ID_ANY, "Click")
  40. hsizer = wx.BoxSizer(wx.HORIZONTAL)
  41. hsizer.Add(self.buttonClick, 0, wx.ALIGN_CENTER)
  42. p.SetSizer(hsizer)
  43.  
  44. # add the text control and button panel
  45. box = wx.BoxSizer(wx.HORIZONTAL)
  46. box.Add(self.text2, 1, wx.EXPAND)
  47. box.Add(p, 0, wx.EXPAND)
  48. return box
  49.  
  50. if __name__ == "__main__":
  51. app = wx.PySimpleApp()
  52. frame = MainFrame(None, wx.ID_ANY, "Test")
  53. frame.Show()
  54. app.MainLoop()
  55.  
.....there are two problems.
1) i want the sizer (that is returned from buildTopPanel() ) to fill the
screen wide/tall. now the text control in it is very small in the
upper-left corner.

2) the scroll bars and borders on the text controls dont appear until i
mouse over them, any ideas?

thanks

Jan 23 '06 #1
1 1909
"py" <co*******@gmai l.com> wrote:

I have the following code:
...
....there are two problems.
1) i want the sizer (that is returned from buildTopPanel() ) to fill the
screen wide/tall. now the text control in it is very small in the
upper-left corner.

2) the scroll bars and borders on the text controls dont appear until i
mouse over them, any ideas?


The panel you create in buildTopPanel has not been added to any sizer. So,
you have the odd condition that the self.text control is controlled by a
sizer, but its parent panel is not. The layout is confused.

You need to build this up bit by bit. The frame gets a panel. The panel
is controlled by a sizer. The panel will contain other panels, added to
the parent panel's sizer. The inner panels may need their own sizers. The
controls owned by the inner panels need to be added to the inner sizers.

The borders don't appear because parts of the panels are overlapping them
in strange ways.

Several folks have suggested that you create the controls from the outside
in, making sure that the control ownership is correct, and then as a
separate step, add those controls to sizers from the inside out. That
works for me, but some kind of structure is needed to make sure that
ownership and sizership are handled completely.

You might try posting on the wxPython mailing list,
http://www.wxpython.org/maillist.php.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jan 24 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
2911
by: Grant Edwards | last post by:
Can anybody recommend a good book on wxPython? Are there any books on wxPython? I've been trying to learn wxPython and/or wax for a few weeks, and I'm just not getting it. wxWindows seems to be more low-level than the other GUI toolkits I've used (Tk, GTK, and Trestle), and there are all sorts exposed details in wxWindows/wxPython that I find weird.
1
2069
by: flupke | last post by:
Hi, i'm trying to convert my java console app to a python gui. Now, the only problem i seem to have at the moment are the resizers for the layout. It seems that for the purpose of what i'm trying to do, specifying the coordinates is easier that fighting with the layout resizers. 1) I have a screen split in 2. Left side is a textcontrol where logging will end up. All text will be appended to the textcontrol. Ideally this should allow...
22
5766
by: dcrespo | last post by:
Hi all... I think wxPython is much better than PyGTK. First of all, PyGTK needs the GTK runtime installed, whereas wxPython is entirely Python's modules, so It facilitates the apps' distribution. Also, PyGTK uses specific controls or widgets of GTK, while wxPython uses native controls of the platform where the app is running. I'm learning both, but at a slow step, so I want to know all the comments about this subject in this group.
3
3498
by: Young H. Rhiu | last post by:
See: http://hilug.org/img/app_layout.GIF I'm implementing an album-like application with wxpython but I'm new to wxPython though I know how to program with python. The problem is that it's not easy for me to deal with drawing layout stuff with wxpython. What layout I'm thinking of looks like the gif image above. The application is about saving some comments for each pictures on the filesystem. There are two windows. The above one is a...
1
161
by: Joe Strout | last post by:
On Oct 23, 2008, at 11:50 AM, Stef Mientki wrote: That's neat -- thank you for making it available. I've just recently been working through some wxPython tutorials, and wondered if there was a simple text-based layout definition format that would let me define my interfaces in a simpler manner. Your page says that the layout is defined in a docstring, but in the sample code, it's actually just in a regular string literal. That's
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10206
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10035
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9851
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8863
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3556
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2811
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.