Hello,
I go thrugh number of tutorials and steel can't find one simple thing (or I can't understand how to do this). My question is this:
if we make "any" function like this:
def myfunc():
#code here:
return
and have a class (gtk or wxWidget) in which we create a Label
class MyLabel():
#code here
#end class
mainloop()
how to change Label inside class MyLabel from myfunc?
I understand how buttons and events work, but i have no idea how to change label, or text from function outside class. ie time triggered timer or any result returned by function which periodicaly change its value?
or is there any way to make label autoupdating? / refreshing?
Tnx for your time and sorry for my english!
3 4371 bvdet 2,851
Recognized Expert Moderator Specialist
Is this what you mean? - >>> class MyLabel(object):
-
... def __init__(self, label="Label 1"):
-
... self.label = label
-
...
-
>>> def modify_label(obj, newlabel="This is a new label"):
-
... obj.label = newlabel
-
...
-
>>> a = MyLabel()
-
>>> a.label
-
'Label 1'
-
>>> modify_label(a)
-
>>> a.label
-
'This is a new label'
-
>>>
Here is source from tutorial, I made some small changes
In short function wanip gets WAN IP and stores it in variable
Button 3 on click calls it and change text2
I wish to change text2 by simply call that function - wanip or any else
how to do that?
here is the source code
tnx for help - # communicate.py
-
-
import wx
-
import urllib
-
-
global IP
-
global myip
-
-
-
-
def wanip():
-
global IP
-
global myip
-
url=urllib.URLopener()
-
html=url.open('http://checkip.dyndns.com')
-
ans=html.read(160)
-
start=ans.find('IP Address')
-
end=ans.find('</body>')
-
IP = str(ans[start:end])
-
return IP
-
-
-
class LeftPanel(wx.Panel):
-
def __init__(self, parent, id):
-
wx.Panel.__init__(self, parent, id, style=wx.BORDER_SUNKEN)
-
global IP
-
self.text1 = parent.GetParent().rightPanel.text1
-
self.text2 = parent.GetParent().rightPanel.text2
-
-
button1 = wx.Button(self, -1, '+', (10, 10))
-
button2 = wx.Button(self, -1, '-', (10, 35))
-
button3 = wx.Button(self, -1, 'Check WAN IP', (10,60))
-
-
self.Bind(wx.EVT_BUTTON, self.OnPlus, id=button1.GetId())
-
self.Bind(wx.EVT_BUTTON, self.OnMinus, id=button2.GetId())
-
self.Bind(wx.EVT_BUTTON, self.CheckIP, id=button3.GetId())
-
-
def OnPlus(self, event):
-
value = int(self.text1.GetLabel())
-
value = value + 1
-
self.text1.SetLabel(str(value))
-
-
def OnMinus(self, event):
-
value = int(self.text1.GetLabel())
-
value = value - 1
-
self.text1.SetLabel(str(value))
-
-
def CheckIP(self,event):
-
global IP
-
#value = str(self.text.GetLabel())
-
#here i call function to check IP and set label
-
self.text2.SetLabel(str(wanip())) #place IP instead of function
-
-
class RightPanel(wx.Panel):
-
def __init__(self, parent, id):
-
wx.Panel.__init__(self, parent, id, style=wx.BORDER_SUNKEN)
-
self.text1 = wx.StaticText(self, -1, '0', (5, 10))
-
self.text2 = wx.StaticText(self, -1, 'checking IP', (5,25))
-
-
class Communicate(wx.Frame):
-
def __init__(self, parent, id, title):
-
wx.Frame.__init__(self, parent, id, title, size=(400, 200))
-
-
panel = wx.Panel(self, -1)
-
self.rightPanel = RightPanel(panel, -1)
-
-
leftPanel = LeftPanel(panel, -1)
-
-
hbox = wx.BoxSizer()
-
hbox.Add(leftPanel, 1, wx.EXPAND | wx.ALL, 5)
-
hbox.Add(self.rightPanel, 1, wx.EXPAND | wx.ALL, 5)
-
-
panel.SetSizer(hbox)
-
self.Centre()
-
self.Show(True)
-
-
app = wx.App()
-
Communicate(None, -1, 'widgets communicate')
-
-
#here is (I think) reference to object in class LeftPanel, text2
-
-
#here i call my func
-
wanip() #args
-
-
app.MainLoop()
-
bvdet 2,851
Recognized Expert Moderator Specialist
Eliminate the global statements - you don't need them. It's not good practice to use global variables anyway. Pass the object you want to modify to your function, and use method SetLabel() in the function. -
# communicate.py
-
-
import wx
-
import urllib
-
-
def wanip(obj):
-
url=urllib.URLopener()
-
html=url.open('http://checkip.dyndns.com')
-
ans=html.read(160)
-
start=ans.find('IP Address')
-
end=ans.find('</body>')
-
IP = str(ans[start:end])
-
obj.SetLabel(IP)
-
return IP
-
-
class LeftPanel(wx.Panel):
-
def __init__(self, parent, id):
-
wx.Panel.__init__(self, parent, id, style=wx.BORDER_SUNKEN)
-
self.text1 = parent.GetParent().rightPanel.text1
-
self.text2 = parent.GetParent().rightPanel.text2
-
-
button1 = wx.Button(self, -1, '+', (10, 10))
-
button2 = wx.Button(self, -1, '-', (10, 35))
-
button3 = wx.Button(self, -1, 'Check WAN IP', (10,60))
-
self.button3 = button3
-
self.Bind(wx.EVT_BUTTON, self.OnPlus, id=button1.GetId())
-
self.Bind(wx.EVT_BUTTON, self.OnMinus, id=button2.GetId())
-
self.Bind(wx.EVT_BUTTON, self.CheckIP, id=button3.GetId())
-
-
def OnPlus(self, event):
-
value = int(self.text1.GetLabel())
-
value += 1
-
self.text1.SetLabel(str(value))
-
-
def OnMinus(self, event):
-
value = int(self.text1.GetLabel())
-
value -= 1
-
self.text1.SetLabel(str(value))
-
-
def CheckIP(self,event):
-
wanip(self.text2)
-
-
class RightPanel(wx.Panel):
-
def __init__(self, parent, id):
-
wx.Panel.__init__(self, parent, id, style=wx.BORDER_SUNKEN)
-
self.text1 = wx.StaticText(self, -1, '0', (5, 10))
-
self.text2 = wx.StaticText(self, -1, 'checking IP', (5,25))
-
-
class Communicate(wx.Frame):
-
def __init__(self, parent, id, title):
-
self.app = wx.App()
-
wx.Frame.__init__(self, parent, id, title, size=(400, 200))
-
panel = wx.Panel(self, -1)
-
self.rightPanel = RightPanel(panel, -1)
-
-
leftPanel = LeftPanel(panel, -1)
-
self.leftPanel = leftPanel
-
hbox = wx.BoxSizer()
-
hbox.Add(leftPanel, 1, wx.EXPAND | wx.ALL, 5)
-
hbox.Add(self.rightPanel, 1, wx.EXPAND | wx.ALL, 5)
-
-
panel.SetSizer(hbox)
-
self.Centre()
-
self.Show(True)
-
-
if __name__ == '__main__':
-
a = Communicate(None, -1, 'widgets communicate')
-
a.app.MainLoop()
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: awan |
last post by:
Is there a function in dotnet which is equivalent as "app.Path" in VB 6?
Thanks in advance!
|
by: Omkar Singh |
last post by:
I am using XmlSerialization and XmlDeserialization for making soap Body part.
Then I am making sopa-header and other part of soap envelope manually. At
last joining all part to get complete soap packet.
Can anyone tell me how can I handle the case of "Any" during serialization
and how to de-serialize the soap-packet containg the field the "Any". As for
de-serization we have to give the class name which have the field of fix
Type.
|
by: Ganesh |
last post by:
I have to change the tartget property of a windows start->Program->X's
shortcut properties using c program. Do we have any function for that ?
please reply me ASAP.. as it is urgent !
|
by: K. G. Suarez |
last post by:
Hello everyone.
I am new to programming and my uncle gave me a copy of "C For Dummies
2nd Edition". I am up to chapter 9 right now. He probably saw me
struggling with "The C Programming Language" by Ritchie and Kernigahn
and felt bad.
Does anyone have experience with this book? I feel that it is helping me
along pretty well. But how much will this book teach me? What would be
the next book to read?
|
by: Lance Geeck |
last post by:
I have many items that I lifted off from Microsoft's website several years
ago. These samples were in VB6.
I now want to convert an application to VB.NET. I am getting an error
that says "As Any is not supported in a declare statement" during the
automated
Conversion process.
Some examples of this are:
Private Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory"(ByRef
| |
by: Lau Lei Cheong |
last post by:
Hello,
Actually, I'm wondering if there's anything of the sort avaliable in
the wild - a developer oriented W3C browser. It's kinda W3C's online
validation service, just that it runs on locahost as an application. It
reads a config file to see what is allowed to pass, and what is depreciated,
and whether fails the deperciated one.
Basically, it'll only render what W3C recommandations and nothing
more. It'll not render any...
|
by: Brahm |
last post by:
hi folks !
What is the equivalent parameter in vb 2005 for "any" from vb 6 ?
Thanks,
Daniel
|
by: joosteto |
last post by:
Subject: pointer to any member function of any class.
The "C++ FAQ Lite" explains how to hand a pointer to a member function
to a signal handler etc, but only to a static function (33.2), to
a fixed class (33.2), any member of a fixed class (33.6), to a fixed
function of any object (functiods, 33.10).
What I wanted was to be able to hand any member function of any
created object to a signal hander etc.
|
by: babakandme |
last post by:
Hi everybody:D
I've a string that contains the name of a class.
Some members told that I can use """Stringizing Operator (#)""", but
the problem is here, that I have the string, & I want something vice-
versa.
As we know with """Stringizing Operator (#)""", we can get the stirng
name of a class or ... str <--- #ClassA
|
by: Peter Duniho |
last post by:
On Fri, 18 Jul 2008 10:41:23 -0700, jmDesktop <needin4mation@gmail.com>
wrote:
Well, that's an interesting example, if for no other reason than that the
DirectShow video capture stuff is a reasonably straight-forward and
natural thing to access from .NET using the p/invoke stuff. You may be
referring to the DirectShow.NET project, which I haven't used but
understand to be a pretty good wrapper for DirectShow.
|
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: 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: 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...
|
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...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| |