473,756 Members | 3,482 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

wxPython - FlatNotebook help

5 New Member
Hi, I'm having some problems with FlatNotebook.py and i hope you can help me. I'm sure that is very easy for an experinced user but i can't figured it out, i just start using wxpython.
The problem is that i don't know how to put diferent king of widgets on every notebook page. For example when i select page1, I want ot see three checkboxes and one button and when i select page2 two buttons and ten radio buttons, all in different positions than the previous page. Considering I have the following sample code how can i do that:
#code
Expand|Select|Wrap|Line Numbers
  1. import wx
  2. import FlatNotebook as FNB
  3. import random
  4.  
  5. class MenuEventFrame(wx.Frame):
  6.  
  7.     def __init__(self, parent, id):
  8.         wx.Frame.__init__(self, parent, id, 'Menus', size=(450, 200), pos=(500,400))
  9.         self.panel=wx.Panel (self, -1)
  10.         #self.panel.SetBackgroundColour ("white")
  11.         menuBar = wx.MenuBar()
  12.         menu1 = wx.Menu()
  13.         menuItem = menu1.Append(-1, "&Exit...")
  14.         menuBar.Append(menu1, "&File")
  15.         self.SetMenuBar(menuBar)
  16.  
  17.         dd="Page1"
  18.         dd1="Page2"
  19.         dd2="Page3"
  20.  
  21.         caption = "test"
  22.  
  23.         stil = FNB.FNB_VC8 | FNB.FNB_DROPDOWN_TABS_LIST | FNB.FNB_TABS_BORDER_SIMPLE | FNB.FNB_BACKGROUND_GRADIENT
  24.         self.book = FNB.FlatNotebook(self, wx.ID_ANY,  style=stil)
  25.         self.book.SetTabAreaColour(wx.Color(0,153,204))
  26.         self.book.AddPage(self.panel, dd, True, -1)
  27.         self.book.AddPage(self.panel, dd1, True, -1)
  28.         self.book.AddPage(self.panel, dd2, True, -1)
  29.         self.book.SetSelection(1)
  30.  
  31.  
  32.  
  33.     def CreatePage(self, caption):
  34.         p = wx.Panel(self.book)
  35.         wx.StaticText(p, -1, caption, (20,20))
  36.         wx.TextCtrl(p, -1, "", (20,40), (150,-1))
  37.         p.SetBackgroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNFACE))
  38.         return p
  39.  
  40.  
  41. if __name__ == '__main__':
  42.     app = wx.PySimpleApp()
  43.     frame = MenuEventFrame(parent=None, id=-1)
  44.     frame.Show()
  45.     app.MainLoop()
  46.  
#end code

In conclusion i want to show different widgets on different notebook pages and of course bind an event to every widget.
Thank you.
May 3 '07 #1
4 5143
bartonc
6,596 Recognized Expert Expert
Thanks for the post (and you came SO close to getting the [ CODE ] tags right - instructions are on the right hand side in REPLY GUIDELINES when you reply).

Instead of
Expand|Select|Wrap|Line Numbers
  1.         self.book.AddPage(self.panel, dd, True, -1)
  2.         self.book.AddPage(self.panel, dd1, True, -1)
  3.         self.book.AddPage(self.panel, dd2, True, -1)
  4.  
You need to create more than on panel (with the widgets that you want on each page and then:
Expand|Select|Wrap|Line Numbers
  1.         self.book.AddPage(self.panel1, dd, True, -1)
  2.         self.book.AddPage(self.panel2, dd1, True, -1)
  3.         self.book.AddPage(self.panel3, dd2, True, -1)
  4.  
Hope that helps!
May 3 '07 #2
MrQ
5 New Member
Hope that helps!
Yes, it helps, thank you very much, but now i'm having a more complex problem, I hope you can help me.
Basically what i want to do is to add a splitter window inside an flat notebook page, then inside the splitter window, on left panel add a label notebook. the problem is neither splitter window nor labelbook is created.
Here is sample code but it's obviously wrong because it's not working. Flatnotebook is created with all 4 pages but not the other ones. :
Expand|Select|Wrap|Line Numbers
  1. import wx
  2. import FlatNotebook as FNB
  3. import random
  4. import data
  5. import LabelBook as LB
  6. from Resources import *
  7.  
  8.  
  9. _pageTexts = ["Hello", "From", "wxPython", "LabelBook", "Demo"]
  10. _pageIcons = ["roll.png", "charge.png", "add.png", "decrypted.png", "news.png"]
  11. _pageColours = [wx.RED, wx.GREEN, wx.WHITE, wx.BLUE, "Pink"]
  12.  
  13. class Panel(wx.Panel):
  14.  
  15.     def __init__(self, parent, colour, label):
  16.  
  17.         wx.Panel.__init__(self, parent, style=wx.BORDER_SUNKEN)
  18.         self.SetBackgroundColour(colour)
  19.  
  20.         label = label + "Demo"
  21.         static = wx.StaticText(self, -1, label, pos=(10, 10))     
  22.  
  23.  
  24. class MenuEventFrame(wx.Frame):
  25.  
  26.     def __init__(self, parent, id):
  27.         wx.Frame.__init__(self, parent, id, 'Demo', size=(640, 480), pos=(500,400))
  28.  
  29.         self.panel=wx.Panel (self, -1)
  30.         self.panel1=wx.Panel (self, -1)
  31.         self.panel2=wx.Panel (self, -1)
  32.         self.panel3=wx.Panel (self, -1)
  33.  
  34.  
  35.         #splitter window
  36.         self.splitter = wx.SplitterWindow(self.panel, -1, style=wx.SP_3D|wx.SP_BORDER|
  37.                                           wx.SP_LIVE_UPDATE|wx.SP_3DSASH)
  38.         sty = wx.BORDER_SUNKEN
  39.         p1 = wx.Window(self.splitter, style=sty)
  40.         p1.SetBackgroundColour("blue")
  41.         wx.StaticText(p1, -1, "Panel One", (5,5))
  42.         p2 = wx.Window(self.splitter, style=sty)
  43.         p2.SetBackgroundColour("sky blue")
  44.         wx.StaticText(p2, -1, "Panel Two", (5,5))
  45.         self.splitter.SetMinimumPaneSize(20)
  46.         self.splitter.SplitVertically(p1, p2, -100)
  47.         self.splitter.SetMinimumPaneSize(120)
  48.  
  49.  
  50.  
  51.         #menu bar
  52.         menuBar = wx.MenuBar()
  53.         menu1 = wx.Menu()
  54.         menuItem = menu1.Append(-1, "&Exit...")
  55.         menuBar.Append(menu1, "&File")
  56.         self.SetMenuBar(menuBar)
  57.         self.Bind(wx.EVT_MENU, self.OnCloseMe, menuItem)
  58.  
  59.  
  60.         #flat notebook
  61.         stil = FNB.FNB_VC8 | FNB.FNB_DROPDOWN_TABS_LIST | FNB.FNB_TABS_BORDER_SIMPLE | FNB.FNB_BACKGROUND_GRADIENT
  62.         self.book = FNB.FlatNotebook(self, wx.ID_ANY,pos=(100, 300),size=(100, 100),  style=stil)
  63.         self.book.SetTabAreaColour(wx.Color(0,153,204))
  64.         self.book.AddPage(self.panel, "Main Application", True, -1)
  65.         self.book.AddPage(self.panel1, "Configuration", True, -1)
  66.         self.book.AddPage(self.panel2, "Favorites", True, -1)
  67.         self.book.AddPage(self.panel3, "Favorites", True, -1)
  68.  
  69.  
  70.         self.book1 = LB.LabelBook(self.panel, -1, style=INB_GRADIENT_BACKGROUND)
  71.         for indx, txts in enumerate(_pageTexts):
  72.             label = "This is panel number %d"%(indx+1)
  73.             self.book.AddPage(Panel(self.book1, _pageColours[indx], label),
  74.                               txts, True, indx)
  75.  
  76.  
  77.     def OnCloseMe(self, event):
  78.         self.Close(True)
  79.  
  80.  
  81. if __name__ == '__main__':
  82.     app = wx.PySimpleApp()
  83.     frame = MenuEventFrame(parent=None, id=-1)
  84.     frame.Show()
  85.     app.MainLoop()
  86.  
  87.  
I will be very grateful if you can help me with this because i'm kinda lost.
May 6 '07 #3
bartonc
6,596 Recognized Expert Expert
I don't know enough about splitter windows to get all the properties set just right.
For that matter I never write the GUI part of my programs. Here is what I consider to be a well-factored wx.Frame definition might look like (as generated by Boa Constructor):
Expand|Select|Wrap|Line Numbers
  1. #Boa:Frame:Frame1
  2.  
  3. import wx
  4.  
  5. def create(parent):
  6.     return Frame1(parent)
  7.  
  8. [wxID_FRAME1, wxID_FRAME1BUTTON1, wxID_FRAME1NOTEBOOK1, wxID_FRAME1NOTEBOOK2, wxID_FRAME1PANEL1,
  9.  wxID_FRAME1SPLITTERWINDOW1, wxID_FRAME1STATICTEXT1,
  10. ] = [wx.NewId() for _init_ctrls in range(7)]
  11.  
  12. class Frame1(wx.Frame):
  13.     def _init_coll_boxSizer1_Items(self, parent):
  14.         # generated method, don't edit
  15.  
  16.         parent.AddWindow(self.panel1, 1, border=0, flag=wx.EXPAND)
  17.  
  18.     def _init_coll_boxSizer2_Items(self, parent):
  19.         # generated method, don't edit
  20.  
  21.         parent.AddWindow(self.notebook1, 1, border=0, flag=wx.EXPAND)
  22.  
  23.     def _init_coll_notebook2_Pages(self, parent):
  24.         # generated method, don't edit
  25.  
  26.         parent.AddPage(imageId=-1, page=self.staticText1, select=True, text='Pages0')
  27.  
  28.     def _init_coll_notebook1_Pages(self, parent):
  29.         # generated method, don't edit
  30.  
  31.         parent.AddPage(imageId=-1, page=self.splitterWindow1, select=True, text='Pages0')
  32.  
  33.     def _init_sizers(self):
  34.         # generated method, don't edit
  35.         self.boxSizer1 = wx.BoxSizer(orient=wx.VERTICAL)
  36.  
  37.         self.boxSizer2 = wx.BoxSizer(orient=wx.VERTICAL)
  38.  
  39.         self._init_coll_boxSizer1_Items(self.boxSizer1)
  40.         self._init_coll_boxSizer2_Items(self.boxSizer2)
  41.  
  42.         self.SetSizer(self.boxSizer1)
  43.         self.panel1.SetSizer(self.boxSizer2)
  44.  
  45.     def _init_ctrls(self, prnt):
  46.         # generated method, don't edit
  47.         wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt, pos=wx.Point(304, 151),
  48.                 size=wx.Size(732, 517), style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
  49.         self.SetClientSize(wx.Size(724, 490))
  50.  
  51.         self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self, pos=wx.Point(0, 0),
  52.                 size=wx.Size(724, 490), style=wx.TAB_TRAVERSAL)
  53.  
  54.         self.notebook1 = wx.Notebook(id=wxID_FRAME1NOTEBOOK1, name='notebook1', parent=self.panel1,
  55.                 pos=wx.Point(0, 0), size=wx.Size(724, 490), style=0)
  56.  
  57.         self.splitterWindow1 = wx.SplitterWindow(id=wxID_FRAME1SPLITTERWINDOW1,
  58.                 name='splitterWindow1', parent=self.notebook1, pos=wx.Point(0, 0), size=wx.Size(716,
  59.                 464), style=wx.SP_LIVE_UPDATE | wx.SP_3D)
  60.         self.splitterWindow1.SetNeedUpdating(True)
  61.  
  62.         self.notebook2 = wx.Notebook(id=wxID_FRAME1NOTEBOOK2, name='notebook2',
  63.                 parent=self.splitterWindow1, pos=wx.Point(0, 0), size=wx.Size(282, 464),
  64.                 style=wx.NB_LEFT)
  65.  
  66.         self.button1 = wx.Button(id=wxID_FRAME1BUTTON1, label='button1', name='button1',
  67.                 parent=self.splitterWindow1, pos=wx.Point(286, 0), size=wx.Size(430, 464), style=0)
  68.         self.splitterWindow1.SplitVertically(self.notebook2, self.button1, 200)
  69.  
  70.         self.staticText1 = wx.StaticText(id=wxID_FRAME1STATICTEXT1, label='staticText1',
  71.                 name='staticText1', parent=self.notebook2, pos=wx.Point(0, 0), size=wx.Size(254,
  72.                 456), style=0)
  73.  
  74.         self._init_coll_notebook1_Pages(self.notebook1)
  75.         self._init_coll_notebook2_Pages(self.notebook2)
  76.  
  77.         self._init_sizers()
  78.  
  79.     def __init__(self, parent):
  80.         self._init_ctrls(parent)
  81.  
  82. if __name__ == '__main__':
  83.     app = wx.PySimpleApp()
  84.     frame = create(parent=None)
  85.     frame.Show()
  86.     app.MainLoop()
  87.  
May 6 '07 #4
bartonc
6,596 Recognized Expert Expert
If you are interested in trying the latest version of Boa Constructor, there are instruction for getting if from the CVS on SourceForge here.
May 6 '07 #5

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

Similar topics

5
4197
by: Daniel Ehrenberg | last post by:
I'm trying to learn wxPython, but I can't seem to find much documentation. The wxPython website says that all advanced (and even some basic) documentation for wxPython is only available in C++ syntax in the main wxWindows documentation. It also says that the samples will help, but I can't seem to make sense of them. Should I just use a not-as-good GUI like Tkinter or a not-as-common one like Anygui or PyUI if I want to have documentation?...
7
11907
by: SeeBelow | last post by:
Do many people think that wxPython should replace Tkinter? Is this likely to happen? I ask because I have just started learning Tkinter, and I wonder if I should abandon it in favor of wxPython. Mitchell Timin -- "Many are stubborn in pursuit of the path they have chosen, few in
15
2910
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
2569
by: timothy.williams | last post by:
I'm trying to install wxPython 2.5.3.1 using Python 2.3.2 on a Fedora 2 machine. I have python in a non-standard place, but I'm using --prefix with the configure script to point to where I have everything. The make install in $WXDIR seemed to go fine. I have the libxw* libraries in my lib/ directory libwx_base-2.5.so@ libwx_gtk_adv-2.5.so.3.0.0* libwx_base-2.5.so.3@ libwx_gtk_core-2.5.so@
10
4974
by: Mario | last post by:
Hello all, I'm trying hard to make possible to print some simple text from python to the default printer using wxPython, after days of internet searches I found this page: http://wiki.wxpython.org/index.cgi/Printing but is impossible to use this script even if I do exactly as said there. I think the script is buggy or I am not able to use it, even if seems very simple to use... Anyone can give me an hint on how to easily and simply print...
0
1661
by: Robin Dunn | last post by:
Announcing ---------- The 2.6.3.0 release of wxPython is now available for download at http://wxpython.org/download.php. There have been many enhancements and fixes implemented in this version, many of which are listed below and at http://wxpython.org/recentchanges.php. What is wxPython?
4
2059
by: tomKeating | last post by:
First I am new to both python and wxPython. I have developed a couple of applications for myself with Paradox, but it is time to move on. I am having difficulty creating a solid background for a flatNotebook widget. I have a page that uses a flexBagSizer to display about 40 pieces of information. For those that I have no further use for I use a staticTextBox, for those I want to be able to present more information for (drill down) I use a...
4
2987
by: stef | last post by:
hello, I'm trying to move from Delphi to Python (move from MatLab to Python already succeeded, also thanks to this discussion group). From the discussions in this list about "the best" GUI for Python, it now seems to me that wxPython is thé choice for my kind of applications. I've no experience with wxPython yet, I just run a few examples and indeed it looks good (as expected from the
2
1190
by: ahlongxp | last post by:
Sorry, I know this is not the most appropriate place to talk about wxPython. But I can't have access to wxPython mail list page(because I don't pay enough). I downloaded python2.5 and wxPython 2.8.4.0 from pythonmac.org and installed them into one of my friends' Mac 10.4.8(intel) and I found wx.lib.flatnotebook and wx.xrc were broken(which are quite OK under both Linux and Windows).
0
9462
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
9886
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...
1
9857
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9722
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
8723
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...
1
7259
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5155
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3817
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2677
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.