1
很高興認識你。我有一個關於使用wxpython的問題。這是我無法控制TextCtrl函數的光標。這是我的wxpython代碼。WxPython [TextCtrl]:使用TextCtrl函數將光標定位到文本結尾的方式。
#!/usr/bin/python
import wx
def get_main_screen_text():
text = "\n [Anyfusion Monitoring System]\n\n"
return text
class Tom(wx.Dialog):
def __init__(self, parent, id, title):
wx.Dialog.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(400, 420))
panel = wx.Panel(self, -1)
vbox = wx.BoxSizer(wx.HORIZONTAL)
vbox1 = wx.BoxSizer(wx.VERTICAL)
vbox2 = wx.BoxSizer(wx.VERTICAL)
self.message = get_main_screen_text()
self.write = wx.TextCtrl(panel, -1, style=wx.TE_MULTILINE, value=self.message)
System_Checkup = wx.Button(panel, 1, label='System_Checkup')
Open_the_Web = wx.Button(panel, 1, label=' Open_the_Web ')
Help_Desk = wx.Button(panel, 1, label=' Help_Desk ')
Exit = wx.Button(panel, 1, label=' Exit ')
vbox1.Add(self.write, 1, wx.EXPAND | wx.TOP | wx.RIGHT | wx.LEFT | wx.BOTTOM, 15)
vbox2.Add(System_Checkup, 0, wx.TOP | wx.TOP | wx.RIGHT, 15)
vbox2.Add(Open_the_Web, 0, wx.TOP | wx.RIGHT, 15)
vbox2.Add(Help_Desk, 0, wx.TOP, 230)
vbox2.Add(Exit, 0, wx.TOP | wx.RIGHT, 15)
vbox.Add(vbox1, 1, wx.EXPAND)
vbox.Add(vbox2, 0, wx.TOP)
self.Bind(wx.EVT_BUTTON, self.EventHandler, id=1)
panel.SetSizer(vbox)
self.Centre()
def EventHandler(self, event):
b=event.GetEventObject().GetLabel()
if b.endswith('System_Checkup'):
self.message = self.message+"\nABC"
self.write.SetValue(self.message)
self.write.SetEditable(False)
self.write.SetScrollPos(wx.VERTICAL,0)
self.write.SetInsertionPoint(0)
self.write.Refresh()
class MyApp(wx.App):
def OnInit(self):
frame = Tom(None, -1, 'Tom')
frame.ShowModal()
frame.Destroy()
return True
if __name__ == "__main__":
app = MyApp()
app.MainLoop()
我想將光標定位到文本的末尾。但是我的程序沒有工作。下面捕獲我的wxpython程序。
非常感謝你。我想盡快..謝謝解決這個問題..
謝謝你。我解決了一個問題。每個功能都是完美的。 –