我正在開發一個使用wxpython的圖形用戶界面,我需要一個選擇時間的textctrl。我用TimePickerCtrl嘗試過,但未能將時間讀取到textctrl中。如果有人分享了一個很好的示例代碼,它會給textctrl增加一個時間,並且可以隨時編輯textctrl,這將是非常棒的。提前感謝。如何在wxpython的文本控件中添加和編輯時間?
0
A
回答
1
你甚至看過wxPython演示嗎?它顯示了3種不同的方法來創建選取器控件:
import wx
import wx.lib.masked as masked
########################################################################
class MyPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
self.mainSizer = wx.BoxSizer(wx.VERTICAL)
text1 = wx.StaticText(self, -1, "12-hour format:", size=(150,-1))
self.time12 = masked.TimeCtrl(self, -1, name="12 hour control")
h = self.time12.GetSize().height
spin1 = wx.SpinButton(self, -1, wx.DefaultPosition, (-1,h), wx.SP_VERTICAL)
self.time12.BindSpinButton(spin1)
self.addWidgets([text1, self.time12, spin1])
text2 = wx.StaticText(self, -1, "24-hour format:")
spin2 = wx.SpinButton(self, -1, wx.DefaultPosition, (-1,h), wx.SP_VERTICAL)
self.time24 = masked.TimeCtrl(
self, -1, name="24 hour control", fmt24hr=True,
spinButton = spin2
)
self.addWidgets([text2, self.time24, spin2])
text3 = wx.StaticText(self, -1, "No seconds\nor spin button:")
self.spinless_ctrl = masked.TimeCtrl(
self, -1, name="spinless control",
display_seconds = False
)
self.addWidgets([text3, self.spinless_ctrl])
self.SetSizer(self.mainSizer)
#----------------------------------------------------------------------
def addWidgets(self, widgets):
""""""
sizer = wx.BoxSizer(wx.HORIZONTAL)
for widget in widgets:
if isinstance(widget, wx.StaticText):
sizer.Add(widget, 0, wx.ALL|wx.CENTER, 5),
else:
sizer.Add(widget, 0, wx.ALL, 5)
self.mainSizer.Add(sizer)
########################################################################
class MyFrame(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, title="Spinner Demo")
panel = MyPanel(self)
self.Show()
if __name__ == "__main__":
app = wx.App(False)
f = MyFrame()
app.MainLoop()
+0
謝謝@Mike。我看了一下wxpython演示。我使用self.Time = TimeCtrl(self.panel,id = -1,value = '00:00:00',pos =(430,108),size = wx.DefaultSize,style = wx.TE_PROCESS_TAB,validator = wx.DefaultValidator ,name =「time」,format ='HHMMSS',fmt24hr = False,displaySeconds = True,spinButton = None,min = None,max = None,limited = None,oob_color =「Yellow」),它對我很有用。 – Aramanethota 2013-04-23 04:46:10
相關問題
- 1. 如何在wxpython中並排添加兩個文本控件
- 2. 如何在wxpython 4.0的單個控件中添加文本和html鏈接?
- 3. 如何添加「彈出編輯控件」
- 4. 如何在wxPython的筆記本頁面中添加和刪除控件?
- 5. 如何在android中動態添加和使用編輯文本?
- 6. wxPython中的不可編輯文本框
- 7. 如何在ajax編輯器控件中使用代碼添加HTML文本
- 8. 如何將文本添加到Visual Studio 2005中的「編輯框」控件
- 9. 如何創建編輯文本控件
- 10. 如何在編輯器爲空時添加佔位符文本
- 11. 在wxpython中使用Windows富編輯控件時,如何解決滾動問題?
- 12. Access 2010子文本編輯和添加
- 13. shell腳本編輯和添加文件中的條目
- 14. 將文本追加到空間不足的編輯控件上?
- 15. 如何在uitableviewcell中添加編輯控件以跟蹤觸摸
- 16. 在webconfig文件中添加或編輯
- 17. 如何在android中限制編輯文本的輸入時間
- 18. PHP在文本中添加或編輯行文件
- 19. 如何在HTML中爲TextBox添加文本合成編輯器
- 20. 如何在編輯文本中添加圖像android
- 21. 如何在JPanel中添加可編輯文本框
- 22. 如何添加編輯文本在本機Tizen應用程序?
- 23. 如何在uwp中的webview控件加載的文本框中添加文本?
- 24. 如何在win32編輯控件中使用「佔位符文本」?
- 25. 在Devexpress控件中如何在富文本編輯器中添加自定義郵件合併字段
- 26. 如何在日誌文件中添加日期和時間戳?
- 27. 從編輯控件中讀取文本
- 28. 如何在Linux中編輯文件並添加換行符?
- 29. 如何在配置文件中添加spring編輯
- 30. ExtJS4 - 如何在Grid中添加文件上傳編輯器?
您應該用'TimePickerCtrl'嘗試更新問題,以便我們可以修復您的嘗試而不是爲您編寫代碼。 – 2013-04-22 05:36:57
是否有任何比TimePickerCtrl添加時間到一個textctrl或spinctrl? – Aramanethota 2013-04-22 05:39:20