Skip to main content
 首页 » 编程设计

python之如何在wx python中制作一个简单的 watch

2025年05月04日18langtianya

谁能告诉我,如何制作一个简单的wxpython

  import wx 
    import time 
 
    class MyFrame(wx.Frame): 
        """ We simply derive a new class of Frame. """ 
        def __init__(self, parent, title): 
            wx.Frame.__init__(self, parent, title=title, size=(200,100)) 
            self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE) 
            self.Show(True) 
 
    app = wx.App(False) 
    frame = MyFrame(None, 'Small editor') 
 
app.MainLoop() 

我想知道我现在如何获取日期时间并将其显示在框架中

请您参考如下方法:

如果您希望在 GUI 内/内部显示日期时间(作为数字,而不是时钟格式),您可以使用 wx.DateTime.Now() 函数。在 wxPython 文档中阅读更多详细信息 here .您可以输入以下内容:

now = wx.DateTime.Now() 
timecheckText = wx.StaticText(panel, -1, "Sample sentence here:\t%s\n"%(now.Format("%c", wx.DateTime.PST)), (3,30)) 


它所做的是在 wx.StaticText 函数中输入日期时间,并在启动后打印当前的日、月、年、时间和时区。此外,无需“导入日期时间”,只需“导入 wx”即可。