472,958 Members | 2,202 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

wxPython - TextCtrl widget problem

In the following code, I have created a panel with a button and a textctrl object on it. I have also created a menubar that will create a new text file (i.e. textctrl object). My problem is that when I create a new file, it displays the textctrl over the top left of my existing panel. I know that the reason is because I have specified the parent as self (i.e. Frame). How do I get the new file to display in the textctrl widget on my panel? I am having the save problems when trying to open a text file. It simply displays the new textctrl over the top left of my panel and I can't figure out a way around it.

Here's the code. Again, I'm trying to get the textctrl widget that is created in the "onNew" method of the "Frame" class to appear in the panel that I created. I know that I didn't have to make a separate class for my panel in the following code, but I want to write an application with multiple panels, so being able to change the text in one or more panels from the menu bar is a must.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/env python
  2.  
  3. import wx
  4.  
  5. class MyGUI(wx.App):
  6.     def OnInit(self):
  7.         self.frame = Frame(None, title = "MyGUI", size = (640, 480))
  8.         self.frame.CenterOnScreen()
  9.         self.frame.Show()
  10.         self.SetTopWindow(self.frame)
  11.         return True
  12.  
  13.  
  14. class Frame(wx.Frame):
  15.     def __init__(self, *args, **kwargs):
  16.         wx.Frame.__init__(self, *args, **kwargs)
  17.         self.panel = CreateMainPanel(self)
  18.         filemenu = wx.Menu()
  19.     filemenu.Append(wx.ID_NEW, "&New")    
  20.     menubar = wx.MenuBar()
  21.     menubar.Append(filemenu, "&File")
  22.     self.SetMenuBar(menubar)    
  23.  
  24.     wx.EVT_MENU(self, wx.ID_NEW, self.onNew)
  25.  
  26.  
  27.     def onNew(self, event):
  28.         """
  29.     Event handler for creating a new file
  30.     """
  31.         self.editor = wx.TextCtrl(self, wx.ID_ANY, style = wx.TE_MULTILINE)
  32.         self.SetTitle("New file -- Unsaved")
  33.  
  34.  
  35. class CreateMainPanel(wx.Panel):
  36.     """
  37.     Creates new panel with a button and textctrl widget on it
  38.     """
  39.     def __init__(self, *args):
  40.         wx.Panel.__init__(self, *args)
  41.  
  42.     self.container1 = wx.BoxSizer(wx.VERTICAL)
  43.     self.container1.Add((0,50), 0, 0)
  44.     self.container1.Add(wx.Button(self, wx.ID_ANY, "Do Something"))
  45.     self.container1.Add((0,50), 0, 0)
  46.  
  47.     self.container2 = wx.GridBagSizer(hgap = 5, vgap = 5)
  48.     self.container2.Add(self.container1, pos = (0, 0))
  49.     self.container2.Add(wx.TextCtrl(self, wx.ID_ANY, style = wx.TE_MULTILINE),
  50.                                     span = (3, 2), pos = (0, 1), 
  51.                     flag = wx.EXPAND | wx.ALL, border = 15)
  52.     self.container2.AddGrowableCol(1)
  53.     self.container2.AddGrowableRow(2)
  54.     self.SetSizer(self.container2)
  55.  
  56.  
  57. def main():
  58.     app = MyGUI()
  59.     app.MainLoop()
  60.  
  61.  
  62. if __name__ == "__main__":
  63.  
  64.     main()
  65.  
Sep 24 '07 #1
1 4538
first of all, i beleive that u have not provided the complete code here. Also the requirements are NOT clear. Hoever, i've listed few things here which may help you out.

In. OnNew method, you are creating a TextCtrl. DO NOT do that. Rather allow the user to type text in the existing TextCtrl. For this, you should change the code at line 49: before adding the textCtrl to Container2, create it and assign it to self.TextCtrl which you can refer to later.
Nov 15 '07 #2

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

Similar topics

3
by: Logan | last post by:
I asked a similar question already in the wxPython mailing list, but did not get an answer up to now: 1.) When using a TextCtrl with styles (color etc.) in wxPython, is it then possible to get a...
3
by: Lo?c Mah? | last post by:
Hello I try to use a Validator for a TxtCtrl placed in a Panel with a Button in order to trigger the Validator and test the content of TxtCtrl. I have looked into wxPython documentation and...
5
by: Jared Russell | last post by:
I've recently decided to try my hand at GUI programming with wxPython, and I've got a couple questions about the general conventions regarding it. To mess around with it, I decided to create a...
1
by: sillyemperor | last post by:
I was a new guy of Python,when i want to test my wxPython app by unittest,it couldn`t work.I fund a stubmaker.py but it only for wxDialog but all widgets.Can someone can tell me how test wxPython...
1
by: PeterG | last post by:
Hi, I am relatively new to Python, and am learning it as part of a university module... Im currently undertaking a project to create an IM server and IM gui client. I have a very basic...
5
by: citronelu | last post by:
I made a small wxPython app that retrieves web data; for visual logging I use a TextCtrl widget, and stdout is redirected to it, something like this: class RedirectOutput: def __init__(self,...
9
by: Tyler | last post by:
Hello All: I am currently working on a project to create an FEM model for school. I was thinking about using wxPython to gather the 12 input variables from the user, then, after pressing the...
4
by: MrQ | last post by:
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...
4
by: Jimmy | last post by:
hi, all I'm having a problem with creating custom events in wxpython. I have a class A handling some data processing work and another class B of GUI matter. I need GUI to display information...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.