我有一个简单的代码:
import wx
class Glowne(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent=parent)
pos = 55
tekst = 'HELLO - position'
font = wx.Font(18, wx.DEFAULT, wx.NORMAL, wx.NORMAL)
wx.StaticText(self, -1, tekst, (300, pos)).SetFont(font)
btn = wx.Button(self, -1, "Change pos", (345, 100))
#self.Bind(wx.EVT_BUTTON, Program.zmiana, btn)
class Program(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY,'Program')
panel_one = Glowne(self)
self.SetSize((800,600))
self.Centre()
if __name__ == "__main__":
app = wx.App(False)
frame = Program()
frame.Show()
app.MainLoop()
点击“更改位置”按钮后如何调整pos变量? 在我的真实节目中,我有类似的东西: 名称 名1 NAME2
"BUTTTON"
我想在点击“BUTTON”后在name2和button之间添加wx.TextCtrl方法。我需要一个框架(添加beetwen name2和按钮)。我不知道如何实现这一点。
EDIT。我需要修改一些代码:
def __init__(self, parent):
global odstep
self.panel = wx.Panel.__init__(self, parent)
odstep = 0
odstep1 = 0
font = wx.Font(13, wx.DEFAULT, wx.NORMAL, wx.NORMAL)
for name in config['rewir1']:
nazwa_zliczana = config['rewir1'][name]
odstep += 22
self.name1 = wx.StaticText(self, -1, name, (300, 10 + odstep))
self.name1.SetFont(font)
btn_usuwanie = wx.Button(self, -1, u"Usuń", (475, 10 + odstep))
self.Bind(wx.EVT_BUTTON, lambda evt, i: Program.Usuwanie(evt, i), btn_usuwanie)
wx.StaticText(self, -1, 'PART I', (365, 0), style=wx.ALIGN_CENTER).SetFont(font)
odstep1 = odstep + 50
print odstep
for name in config['rewir2']:
nazwa_zliczana = config['rewir2'][name]
odstep1 += 22
self.name2 = wx.StaticText(self, -1, name, (300, 50 + odstep1))
self.name2.SetFont(font)
btn_usuwanie_2 = wx.Button(self, -1, u"Usuń", (475, 50 + odstep1))
self.Bind(wx.EVT_BUTTON, lambda evt, i: Program.Usuwanie(evt, i), btn_usuwanie_2)
print odstep1
wx.StaticText(self, -1, 'PART II', (365, 80 + odstep), style=wx.ALIGN_CENTER).SetFont(font)
self.btn = wx.Button(self, -1, "Change panel", (345, 500))
self.btn_dodaj_rewir1 = wx.Button(self, -1, "Add name", (345, 42 + odstep))
self.btn_dodaj_rewir2 = wx.Button(self, -1, "Add name", (345, 84 + odstep1))
self.Bind(wx.EVT_BUTTON, self.new_name, self.btn_dodaj_rewir1)
答案 0 :(得分:1)
wx.StaticText
instanced。稍后改变它的属性。
SetPosition
方法更改位置。EVT_BUTTON
事件绑定到事件处理程序(change_pos
,代码如下)。class Glowne(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent=parent)
tekst = 'HELLO - position'
font = wx.Font(18, wx.DEFAULT, wx.NORMAL, wx.NORMAL)
self.text = wx.StaticText(self, -1, tekst, (300, 55)) # Save for later use
self.text.SetFont(font)
btn = wx.Button(self, -1, "Change pos", (345, 100))
btn.Bind(wx.EVT_BUTTON, self.change_pos)
def change_pos(self, event):
x, y = self.text.Position
self.text.SetPosition((x, y + 10))