import wx
class Mywin(wx.Frame):
def __init__(self, parent, title):
super(Mywin, self).__init__(parent, title=title, size=(350, 250))
panel = wx.Panel(self)
vbox = wx.BoxSizer(wx.VERTICAL)
hbox1 = wx.BoxSizer(wx.HORIZONTAL)
hbox1.Add(wx.StaticText(panel, -1, "Text Field"), 1, wx.ALL, 5)
t1 = wx.TextCtrl(panel)
hbox1.Add(t1, 1, wx.ALL, 5)
t1.Bind(wx.EVT_TEXT, self.OnKeyTyped)
vbox.Add(hbox1)
hbox2 = wx.BoxSizer(wx.HORIZONTAL)
hbox2.Add(wx.StaticText(panel, -1, "password field"), 1, wx.ALL, 5)
t2 = wx.TextCtrl(panel, style=wx.TE_PASSWORD)
hbox2.Add(t2, 1, wx.ALL, 5)
vbox.Add(hbox2)
t2.SetMaxLength(5)
t2.Bind(wx.EVT_TEXT_MAXLEN, self.OnMaxLen)
hbox3 = wx.BoxSizer(wx.HORIZONTAL)
hbox3.Add(wx.StaticText(panel, -1, "Multiline Text"), 1, wx.ALL, 5)
t3 = wx.TextCtrl(panel, size=(-1, 100), style=wx.TE_MULTILINE)
hbox3.Add(t3, 1, wx.ALL, 5)
vbox.Add(hbox3)
# self.t3.Bind(wx.EVT_TEXT_ENTER, self.OnEnterPressed)
hbox4 = wx.BoxSizer(wx.HORIZONTAL)
hbox4.Add(wx.StaticText(panel, -1, "Read only text"), 1, wx.ALL, 5)
self.t4 = wx.TextCtrl(panel, value="ReadOnly Text",style = wx.TE_READONLY|wx.TE_CENTER)
hbox4.Add(self.t4, 1, wx.ALL, 5)
vbox.Add(hbox4)
panel.SetSizer(vbox)
self.Centre()
self.Show()
self.Fit()
def OnKeyTyped(self, event):
print(event.GetString())
def OnEnterPressed(self, event):
print("Enter pressed")
def OnMaxLen(self, event):
print("Maximum length reached")
app = wx.App()
Mywin(None, 'TextCtrl demo')
app.MainLoop()
wxPython
因不支援副檔名為xmls的檔案,故須透過 offiece 轉成xls,也不能直接從檔名改,否則一樣不支援 Ref. Localizable.strings2Excel
Jun 1, 2022Ref. Python内置库:configparser(INI格式配置文件解析)
Oct 25, 2021Ref. 【python的異常處理】異常的捕捉
Jul 22, 2021調整了範例,讓 timer t 可在任意位置取消 timer 的運作,指令 t.cancel() import threading # global t t = None def set_interval(func, sec): global t
Jul 21, 2021or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up