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. -
#!/usr/bin/env python
-
-
import wx
-
-
class MyGUI(wx.App):
-
def OnInit(self):
-
self.frame = Frame(None, title = "MyGUI", size = (640, 480))
-
self.frame.CenterOnScreen()
-
self.frame.Show()
-
self.SetTopWindow(self.frame)
-
return True
-
-
-
class Frame(wx.Frame):
-
def __init__(self, *args, **kwargs):
-
wx.Frame.__init__(self, *args, **kwargs)
-
self.panel = CreateMainPanel(self)
-
filemenu = wx.Menu()
-
filemenu.Append(wx.ID_NEW, "&New")
-
menubar = wx.MenuBar()
-
menubar.Append(filemenu, "&File")
-
self.SetMenuBar(menubar)
-
-
wx.EVT_MENU(self, wx.ID_NEW, self.onNew)
-
-
-
def onNew(self, event):
-
"""
-
Event handler for creating a new file
-
"""
-
self.editor = wx.TextCtrl(self, wx.ID_ANY, style = wx.TE_MULTILINE)
-
self.SetTitle("New file -- Unsaved")
-
-
-
class CreateMainPanel(wx.Panel):
-
"""
-
Creates new panel with a button and textctrl widget on it
-
"""
-
def __init__(self, *args):
-
wx.Panel.__init__(self, *args)
-
-
self.container1 = wx.BoxSizer(wx.VERTICAL)
-
self.container1.Add((0,50), 0, 0)
-
self.container1.Add(wx.Button(self, wx.ID_ANY, "Do Something"))
-
self.container1.Add((0,50), 0, 0)
-
-
self.container2 = wx.GridBagSizer(hgap = 5, vgap = 5)
-
self.container2.Add(self.container1, pos = (0, 0))
-
self.container2.Add(wx.TextCtrl(self, wx.ID_ANY, style = wx.TE_MULTILINE),
-
span = (3, 2), pos = (0, 1),
-
flag = wx.EXPAND | wx.ALL, border = 15)
-
self.container2.AddGrowableCol(1)
-
self.container2.AddGrowableRow(2)
-
self.SetSizer(self.container2)
-
-
-
def main():
-
app = MyGUI()
-
app.MainLoop()
-
-
-
if __name__ == "__main__":
-
-
main()
-
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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: 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...
|
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,...
|
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...
|
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...
|
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...
|
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=()=>{
|
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...
|
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...
|
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...
|
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 :...
|
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...
|
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...
|
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...
|
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...
| |