473,725 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

wxPython - TextCtrl widget problem

1 New Member
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 4583
Murali S Iyengar
1 New Member
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
3021
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 'list' (or anything) from the widget which tells you which styles are used in the widget (and where!; 'beginning of style', 'end of style', 'type of style' ...)? 2.) Is it possible to set something like a mark in a TextCtrl?
3
7540
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 demo and searched in google, but I am still unsuccessful yet. My problem is that I do not manage to call the Validate() method of my Validator from the button handler.
5
1421
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 small app to check my Gmail. I want something that will just sit in my system tray checking for new emails every ten minutes or so. As such, I have no need for an actual window anywhere. So I'm wondering if I should still use a Frame or not. ...
1
2080
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 by unittest?Thanks
1
2798
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 server, and a basic gui client. I can get my
5
2865
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, objectTxtCtrl): self.out = objectTxtCtrl def write(self, string): self.out.WriteText(string)
9
4443
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 "Run" button, the GUI would close, and the 12 input variables would then be available for the rest of the program. So far, what I have been able to do is mostly a reverse engineering job to get the frame to look right and return the text variable...
4
5141
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 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...
4
2848
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 when data in A is updated. I know cutom events in wxpython may work. But I found no material paricularly helpful :(
0
8889
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
8752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9401
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...
1
9179
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
9116
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
8099
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
4519
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...
2
2637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
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.