如何使python更新或刷新???(wxpython)
在哪里以及如何使其更新或刷新 如果我按下底部的按钮(按钮1、按钮2、按钮3),我想更改上下文、位置等 但我不知道怎么做。你能帮我一下吗 代码如下:如何使python更新或刷新???(wxpython),python,wxpython,refresh,reload,Python,Wxpython,Refresh,Reload,在哪里以及如何使其更新或刷新 如果我按下底部的按钮(按钮1、按钮2、按钮3),我想更改上下文、位置等 但我不知道怎么做。你能帮我一下吗 代码如下: import wx class mainFrame(wx.Frame): def __init__(self, parent, id): wx.Frame.__init__(self, parent, id, "refresh&update", size=(900,600)) self.count
import wx
class mainFrame(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, "refresh&update", size=(900,600))
self.count = 0
if self.count == 0:
self.text = wx.TextCtrl(self, pos=(0, 0), size=(100, 100))
self.text.AppendText('00000000')
self.text1 = wx.TextCtrl(self, pos=(100, 100), size=(100, 100))
self.text1.AppendText('00000000')
self.text2 = wx.TextCtrl(self, pos=(170, 250), size=(100, 100))
self.text2.AppendText('00000000')
if self.count == 1:
self.text3 = wx.TextCtrl(self, pos=(100, 50), size=(100, 100))
self.text3.AppendText('1111111')
buttonl = wx.Button(self, label="1111111", pos=(450,100), size=(100,100))
button2 = wx.Button(self, label="1111111", pos=(250,100), size=(100,100))
if self.count == 2:
self.text6 = wx.TextCtrl(self, pos=(0, 0), size=(100, 100))
self.text6.AppendText('22222222')
self.text = wx.TextCtrl(self, pos=(100, 100), size=(100, 100))
self.text.AppendText('22222222')
button3 = wx.Button(self, label="22", pos=(250,170), size=(100,100))
button4 = wx.Button(self, label="22", pos=(350,170), size=(100,100))
button1 = wx.Button(self, label="count0", pos=(150,450), size=(200,100))
button1.Bind(wx.EVT_BUTTON, self.OnB1)
button2 = wx.Button(self, label="count1", pos=(400,450), size=(200,100))
button2.Bind(wx.EVT_BUTTON, self.OnB2)
button3 = wx.Button(self, label="count2", pos=(650,450), size=(200,100))
button3.Bind(wx.EVT_BUTTON, self.OnB3)
def OnB1(self, event):
self.count = 0
def OnB2(self, event):
self.count = 1
def OnB3(self, event):
self.count = 2
app = wx.App()
frame = mainFrame(None, id = -1).Show()
app.MainLoop()
############################# error////////////////////////////////////
self.counts = [
[ #count =0
image=wx.Image(u"aaa.jpg",wx.BITMAP_TYPE_ANY),
self.bitmap_1 = wx.StaticBitmap(self, wx.ID_ANY, wx.BitmapFromImage(image.Rescale(350, 350)), (490,420)),
self.bitmap_1.Bind(wx.EVT_LEFT_DOWN, self.onClick,
],
[ #count = 1
button_cancel = wx.Button(self, label="취소", pos=(490,550), size=(300,150)),
button_cancel.SetFont(wx.Font(40, wx.ROMAN, wx.SLANT, wx.BOLD, 0, "")),
],
]
##################################
但在这个数组中,我没有发现如何
self.counts = [
[ #count =0
image=wx.Image(u"aaa.jpg",wx.BITMAP_TYPE_ANY),
self.bitmap_1 = wx.StaticBitmap(self, wx.ID_ANY, wx.BitmapFromImage(image.Rescale(350, 350)), (490,420)),
self.bitmap_1.Bind(wx.EVT_LEFT_DOWN, self.onClick,
],
[ #count = 1
button_cancel = wx.Button(self, label="취소", pos=(490,550), size=(300,150)),
button_cancel.SetFont(wx.Font(40, wx.ROMAN, wx.SLANT, wx.BOLD, 0, "")),
],
]
您只需更改变量
计数
<代码>\uuuu init\uuuu只调用一次。没有添加新文本或任何更改,只更改了变量计数。在按钮侦听器中,您需要添加代码来更改文本
在OnB*
功能中:
def OnB1(self, event):
self.count = 0
self.text.SetLabel("%06d"%self.count)
也许你在找这样的东西
import wx
def BoundButton(*args,**kwargs):
callback = kwargs.pop("callback",lambda e:None)
btn = wx.Button(*args,**kwargs)
btn.Bind(wx.EVT_BUTTON,callback)
return btn
def hide_all(itm):
if isinstance(itm,(list,tuple)):
for i in itm:
hide_all(i)
else:
itm.Hide()
def show_all(itm):
if isinstance(itm,(list,tuple)):
for i in itm:
show_all(i)
else:
itm.Show()
class mainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "refresh&update", size=(900,600))
self.count = 0
self.counts = [
[ #count =0
wx.TextCtrl(self,-1,'{0:08d}'.format(0), pos=(0, 0), size=(100, 100)),
wx.TextCtrl(self,-1,'{0:08d}'.format(0), pos=(100, 100), size=(100, 100)),
wx.TextCtrl(self,-1,'{0:08d}'.format(0), pos=(170, 250), size=(100, 100)),
BoundButton(self, label="count0", pos=(150,450), size=(200,100),callback=self.OnB1),
BoundButton(self, label="count1", pos=(400,450), size=(200,100),callback=self.OnB1),
BoundButton(self, label="count2", pos=(650,450), size=(200,100),callback=self.OnB1),
],
[ #count = 1
wx.TextCtrl(self,-1,"{0:08d}".format(1), pos=(100, 50), size=(100, 100)),
BoundButton(self, label="1111111", pos=(450,100), size=(100,100),callback=self.OnB2),
BoundButton(self, label="1111111", pos=(250,100), size=(100,100),callback=self.OnB2),
],
]
self.updateFromCount()
def OnB1(self,e):
self.Toggle(1)
def OnB2(self,e):
self.Toggle(0)
def Toggle(self,i):
self.count = i
self.updateFromCount()
def updateFromCount(self):
hide_all(self.counts)
for i in range(self.count+1):
show_all(self.counts[i])
a = wx.App(redirect=0)
f = mainFrame()
f.Show()
a.MainLoop()
或者更简单的
self.text.SetLabel(“%06d”%self.count)
@JoranBeasley:是的,也许我不应该回答这些问题,因为我缺乏使用wxWidgets的经验。哈哈,谢谢@乔兰比斯利:@Bair:非常感谢你。我明白它为什么不起作用。但我找不到正确的答案。如何创建按钮1、按钮2、按钮3、按钮4??按照OnB*代码,它只能更改文本。我想创建按钮和不相关的text.SetLabel(OnB1->text.AppendText('1235535')。什么?我不明白你在问什么for@Joran比斯利:我的意思是我怎样才能使它正确或有效。不可能吗???你能教我一些可以通过几个按钮进行更改的代码吗?非常感谢。你的回答对我很有帮助。我能再问一件事吗?我试图应用我的代码。但是我在self.counts[]中有一些错误(我的问题代码底部有错误代码)。
import wx
def BoundButton(*args,**kwargs):
callback = kwargs.pop("callback",lambda e:None)
btn = wx.Button(*args,**kwargs)
btn.Bind(wx.EVT_BUTTON,callback)
return btn
def hide_all(itm):
if isinstance(itm,(list,tuple)):
for i in itm:
hide_all(i)
else:
itm.Hide()
def show_all(itm):
if isinstance(itm,(list,tuple)):
for i in itm:
show_all(i)
else:
itm.Show()
class mainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "refresh&update", size=(900,600))
self.count = 0
self.counts = [
[ #count =0
wx.TextCtrl(self,-1,'{0:08d}'.format(0), pos=(0, 0), size=(100, 100)),
wx.TextCtrl(self,-1,'{0:08d}'.format(0), pos=(100, 100), size=(100, 100)),
wx.TextCtrl(self,-1,'{0:08d}'.format(0), pos=(170, 250), size=(100, 100)),
BoundButton(self, label="count0", pos=(150,450), size=(200,100),callback=self.OnB1),
BoundButton(self, label="count1", pos=(400,450), size=(200,100),callback=self.OnB1),
BoundButton(self, label="count2", pos=(650,450), size=(200,100),callback=self.OnB1),
],
[ #count = 1
wx.TextCtrl(self,-1,"{0:08d}".format(1), pos=(100, 50), size=(100, 100)),
BoundButton(self, label="1111111", pos=(450,100), size=(100,100),callback=self.OnB2),
BoundButton(self, label="1111111", pos=(250,100), size=(100,100),callback=self.OnB2),
],
]
self.updateFromCount()
def OnB1(self,e):
self.Toggle(1)
def OnB2(self,e):
self.Toggle(0)
def Toggle(self,i):
self.count = i
self.updateFromCount()
def updateFromCount(self):
hide_all(self.counts)
for i in range(self.count+1):
show_all(self.counts[i])
a = wx.App(redirect=0)
f = mainFrame()
f.Show()
a.MainLoop()