Hi All,
Apologies if this should be seriously obvious. But I am quite new to
Python and it is not quite so obvious yet.
I have a GUI which will eventually load and display database
information. I want the user to be able to browse for a database and
then load it. My problem relates to how I set the value of a TextCtrl
once the user has selected the database they wish to load.
Here is a snip of my code:
import wx
import os
class TestFrame(wx.Fr ame):
def __init__(self):
wx.Frame.__init __(self, None, -1, "Code Snip")
panel = wx.Panel(self)
databaseLbl = wx.StaticText(p anel, -1, "Database:" )
database = wx.TextCtrl(pan el, -1, "")
databaseBtn = wx.Button(panel , -1, "Browse")
self.Bind(wx.EV T_BUTTON, self.OnBrowse, databaseBtn)
fetchSizer = wx.BoxSizer(wx. HORIZONTAL)
fetchSizer.Add( databaseLbl)
fetchSizer.Add( database, -1, wx.LEFT |wx.RIGHT, 5)
fetchSizer.Add( databaseBtn)
panel.SetSizer( fetchSizer)
def OnBrowse(self, event):
wildcard = "Access Database (*.mdb) | *.mdb | Access Database
(*.MDB) | *.MDB | All Files (*.*) | *.*"
dialog = wx.FileDialog(N one, "Choose an database",
os.getcwd(), "", wildcard, wx.OPEN)
if dialog.ShowModa l() == wx.ID_OK:
path = dialog.GetPath( )
############### ############### ###########
# NOW SET TEXTCTRL "database" TO "path"
panel.database. SetLabel(path)
############### ############### ###########
dialog.Destroy( )
app = wx.PySimpleApp( )
TestFrame().Sho w()
app.MainLoop()
The current code returns that "global name 'panel' is not defined" so
I must be referring to it in the wrong way. Can any body help? Any
directions towards any well recommended tutorials would also be
appreciated.
Thank you in advance for your time.
DevonDan 3 2118
Le Thursday 19 June 2008 11:48:54 dp_pearce, vous avez écrit*:
Hi All,
Apologies if this should be seriously obvious. But I am quite new to
Python and it is not quite so obvious yet.
I have a GUI which will eventually load and display database
information. I want the user to be able to browse for a database and
then load it. My problem relates to how I set the value of a TextCtrl
once the user has selected the database they wish to load.
Here is a snip of my code:
import wx
import os
class TestFrame(wx.Fr ame):
def __init__(self):
wx.Frame.__init __(self, None, -1, "Code Snip")
panel = wx.Panel(self)
databaseLbl = wx.StaticText(p anel, -1, "Database:" )
database = wx.TextCtrl(pan el, -1, "")
databaseBtn = wx.Button(panel , -1, "Browse")
self.Bind(wx.EV T_BUTTON, self.OnBrowse, databaseBtn)
fetchSizer = wx.BoxSizer(wx. HORIZONTAL)
fetchSizer.Add( databaseLbl)
fetchSizer.Add( database, -1, wx.LEFT |wx.RIGHT, 5)
fetchSizer.Add( databaseBtn)
panel.SetSizer( fetchSizer)
def OnBrowse(self, event):
wildcard = "Access Database (*.mdb) | *.mdb | Access Database
(*.MDB) | *.MDB | All Files (*.*) | *.*"
dialog = wx.FileDialog(N one, "Choose an database",
os.getcwd(), "", wildcard, wx.OPEN)
if dialog.ShowModa l() == wx.ID_OK:
path = dialog.GetPath( )
############### ############### ###########
# NOW SET TEXTCTRL "database" TO "path"
panel.database. SetLabel(path)
############### ############### ###########
dialog.Destroy( )
app = wx.PySimpleApp( )
TestFrame().Sho w()
app.MainLoop()
The current code returns that "global name 'panel' is not defined"
'panel' is local to your __init__ function, so it's not available elsewhere.
You should store it as an instance attribute instead :
# in __init__:
self.panel = wx.Panel(self)
# in OnBrowse
self.panel.data base.SetLabel(p atrh)
note that unlike some other languages, panel and self.panel are two distinct
variables, so you should replace _all_ references to panel by self.panel.
--
Cédric Lucantis
Thank you very much Cédric. I thought it would be something very
straight forward.
On Jun 19, 5:25*am, dp_pearce <dp_pea...@hotm ail.comwrote:
Thank you very much Cédric. I thought it would be something very
straight forward.
Just an FYI. There's also a wxPython specific mailing list that I
highly recommend. You can learn a lot just reading other people issues
and how they get them fixed.
Here's the link: http://wxpython.org/maillist.php
-------------------
Mike Driscoll
Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ringwraith |
last post by:
Hello!
How to detect in Python that some click action was performed in some module
imported by my main module?
Let's assume I have a tree.py module that implements all functionality of a
tree view widget and my sample application (let's say myapp.py) that imports
those tree module to create tree view control inside the main frame. I want
in my application to have some method that responds immediately (!!!!) to
click action performed...
|
by: Grant Edwards |
last post by:
I've decided to learn wxPython, and I'm afraid I just don't
grok the whole "id" thing where you have to pull unique
integers out of your, er, the air and then use those to refer
to objects:
From whe wxPython wiki examples:
self.button =wxButton(self, 10, "Save", wxPoint(200, 325))
EVT_BUTTON(self, 10, self.OnClick)
|
by: John Salerno |
last post by:
Ah, the object-oriented stuff is just so FUN! :) Here's my code,
followed by the error. I thought I was referring to the 'text' attribute
correctly, but it seems not.
import wx
class InputForm(wx.Frame):
def __init__(self, parent, id, title, pos=wx.DefaultPosition,
|
by: janama |
last post by:
Hi all,
Using wx
When adding a second timer as i have the first, the second timer
adding stops the first timer (updating or stops?) . In this example im
updating a uptime and localtime label. It works fine for displaying the
last "self.startTimer2()" called. But prevents the previous
self.startTimer1() from running . Im doing something fundamentally
wrong i guess?
|
by: John Salerno |
last post by:
I'd be curious to know if this works any differently on other
computers/platforms or while other things are happening in the
background. I can't tell if it's the Timer object that isn't keep
accurate time (although a test with time.time() seems to show that it
is), or if I'm just messing up my algorithm to fill the progress bar. If
I put in 10 seconds, the progress bar will be fully filled at the end,
but if you put 30, it doesn't. As the...
| |
by: gopython |
last post by:
Hi,
I just started coding with wxPython. The idea is to be able to change the gui dynamically. I am trying to change the static text inside the panel after the panel is created without user input/interaction, and I am not very successful with it. Below is my codes:
import wx
class MyForm (wx.Panel):
def __init__ (self, parent, id):
wx.Panel.__init__(self, parent, id)
|
by: Matt Bitten |
last post by:
I've got a wxPython program that needs to do some drawing on a DC on a
regular basis, whether or not a paint event happens. I know how to
make a ClientDC to do the drawing in, and I know what drawing calls to
make. But how do I make it all happen? After I call MainLoop, none of
my code gets called unless there is an event. And there is no event,
so my code doesn't get called. What do I do?
|
by: Jimmy |
last post by:
Hi, wxPython is cool and easy to use, But I ran into a problem
recently when I try to write a GUI.
The thing is I want to periodically update the content of StatixText
object, so after create them, I pack them into a list...the problem
comes when I later try to extract them from the list! I don't know
why?
my code is as following:
import wx, socket
import thread
|
by: Gandalf |
last post by:
I try to reach a specific wx StaticText element's text and to change
it by clicking on a button
now let's say the this is my element:
wx.StaticText(panel, 15, "Hello" ,(30, 70) , style=wx.ALIGN_CENTRE)
And this is my EVT_BUTTON bind function :
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
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...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |