制作gui
选项卡学习
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# author:SunXiuWen
# datetime:2023/02/10
"""
https://iowiki.com/wxpython/wx_textctrl_class.html
https://blog.csdn.net/weixin_55556883/article/details/122590380
https://blog.csdn.net/Logintern09/article/details/126685315
https://docs.wxpython.org/wx.DirPickerCtrl.html?highlight=dirpicker#wx.DirPickerCtrl
https://blog.csdn.net/cubejava/article/details/128480069
https://blog.csdn.net/weixin_34357928/article/details/92267787
"""
import wx
class Tab1p(wx.Panel): # 第一个选项卡类,类继承于wx.Panel
def __init__(self, parent):
wx.Panel.__init__(self, parent)
t = wx.StaticText(self, -1, "选项卡1", (20, 20))
button = wx.Button(self,
label="拉取Pull",
pos=(125, 10), # 指定按钮在画板中的位置
size=(50, 50)) # 指定按钮的大小
class Tab2p(wx.Panel): # 第二个选项卡类
def __init__(self, parent):
wx.Panel.__init__(self, parent)
t = wx.StaticText(self, -1, "选项卡2", (20, 20))
class Tab3p(wx.Panel): # 第三个选项卡类
def __init__(self, parent):
wx.Panel.__init__(self, parent)
t = wx.StaticText(self, -1, "选项卡3", (20, 20))
class MainWindow(wx.Frame): # 主窗口类
def __init__(self):
wx.Frame.__init__(self, parent=None, id=-1, title='选项卡展示', size=(640, 480))
p = wx.Panel(self) # 创建面板
self.nb = wx.Notebook(p) # 创建一个wx.Notebook对象
self.tab1 = Tab1p(self.nb) # 创建一个选项卡控件
self.tab2 = Tab2p(self.nb)
self.tab3 = Tab3p(self.nb)
self.nb.AddPage(self.tab1, '选项卡(1)') # 将选项卡添加到wx.Notebook小部件上
self.nb.AddPage(self.tab2, '选项卡(2)')
self.nb.AddPage(self.tab3, '选项卡(3)')
sizer = wx.BoxSizer()
sizer.Add(self.nb, 1, wx.EXPAND)
p.SetSizer(sizer)
p.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.tabChange) # 绑定选项卡切换事件
def tabChange(self, evt):
print('当前是第{}块选项卡'.format(self.nb.GetSelection() + 1))
app = wx.App()
frame = MainWindow()
frame.Show()
app.MainLoop()
时间选择器
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# author:SunXiuWen
# datetime:2023/02/13
import wx
import wx.adv
import datetime
"""
https://www.bilibili.com/read/cv11509656/
"""
class wCalendar(wx.Frame):
def __init__(self, parent, id, *p):
super().__init__(parent, id)
self.parent = parent
def dateInit(self, *p):
dtime = p[0][0]
curdate = datetime.date.today()
yy = curdate.year
if len(p[0]) > 1:
yy = yy + p[0][1]
wxc = wx.adv.CalendarCtrl(self, -1, pos=(0, 0), size=(220, 220),
date=datetime.datetime(yy, curdate.month, curdate.day),
style=wx.adv.DP_ALLOWNONE)
wxc.Bind(wx.adv.EVT_CALENDAR, lambda e: self.getDateData(wxc, dtime))
self.SetSize((260, 260))
self.SetMaxSize((260, 260))
self.SetTitle('选择日期')
self.Centre()
# self.Show(True)
def getDateData(self, hander, dT):
ss = hander.GetDate()
nD = '%s-%s-%s' % (ss.year, ss.month + 1, ss.day)
dT.SetValue(nD)
self.Close()
app = wx.App()
f = wCalendar(None, wx.ID_ANY)
f.show()
app.MainLoop()
标签:__,tkinter,parent,每日,init,模块,选项卡,self,wx
From: https://www.cnblogs.com/sunxiuwen/p/17289664.html