2013-04-22 20 views
0

我正在開發一個使用wxpython的圖形用戶界面,我需要一個選擇時間的textctrl。我用TimePickerCtrl嘗試過,但未能將時間讀取到textctrl中。如果有人分享了一個很好的示例代碼,它會給textctrl增加一個時間,並且可以隨時編輯textctrl,這將是非常棒的。提前感謝。如何在wxpython的文本控件中添加和編輯時間?

+0

您應該用'TimePickerCtrl'嘗試更新問題,以便我們可以修復您的嘗試而不是爲您編寫代碼。 – 2013-04-22 05:36:57

+0

是否有任何比TimePickerCtrl添加時間到一個textctrl或spinctrl? – Aramanethota 2013-04-22 05:39:20

回答

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

相關問題