Python-GUI-wxPython-控件

1 需求


2 接口


 3.* 控件:wx.StaticText

import wx


class MainFrame(wx.Frame):
    def __init__(self, *args, **kwargs):
        super(MainFrame, self).__init__(*args, **kwargs)

        self.init_ui()
        self.Center()
        self.Maximize()

    def init_ui(self):
        static_text = wx.StaticText(parent=self,
                                    id=-1,
                                    label="Hello World",
                                    pos=wx.DefaultPosition,
                                    size=wx.DefaultSize,
                                    style=0,
                                    name="textCtrl")


if __name__ == "__main__":
    app = wx.App()
    frame = MainFrame(None, title="wxPython Demo")
    frame.Show()
    app.MainLoop()

3.* 控件:wx.TextCtrl

import wx


class MainFrame(wx.Frame):
    def __init__(self, *args, **kwargs):
        super(MainFrame, self).__init__(*args, **kwargs)

        self.init_ui()
        self.Center()
        self.Maximize()

    def init_ui(self):
        text_control = wx.TextCtrl(parent=self,
                                   id=-1,
                                   value="",
                                   pos=wx.DefaultPosition,
                                   size=wx.DefaultSize,
                                   style=0,
                                   validator=wx.DefaultValidator,
                                   name="textCtrl")


if __name__ == "__main__":
    app = wx.App()
    frame = MainFrame(None, title="wxPython Demo")
    frame.Show()
    app.MainLoop()

3.* 控件:wx.Button

import wx


class MyFrame(wx.Frame):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.text_ctrl = None

        self.init_ui()

        self.Center()

        self.Maximize()

    def init_ui(self):
        panel = wx.Panel(self)

        sizer = wx.BoxSizer(wx.HORIZONTAL)

        btn = wx.Button(panel, label="测试")
        self.text_ctrl = wx.TextCtrl(panel)

        sizer.Add(btn)
        sizer.Add(self.text_ctrl)

        btn.Bind(wx.EVT_BUTTON, self.on_btn)

        panel.SetSizer(sizer)

    def on_btn(self, event):
        self.text_ctrl.SetValue("hello world")


if __name__ == "__main__":
    app = wx.App()
    frame = MyFrame(None, title="wxPython Demo")
    frame.Show()
    app.MainLoop()

3.* 控件:wx.RadioButton

import wx


class MyFrame(wx.Frame):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.init_ui()

        self.Center()

        self.Maximize()

    def init_ui(self):
        panel = wx.Panel(self)

        sizer = wx.BoxSizer(wx.HORIZONTAL)

        static_text = wx.StaticText(panel, label="Gender: ")

        male_radio_btn = wx.RadioButton(panel, label="Male", style=wx.RB_GROUP)
        female_radio_btn = wx.RadioButton(panel, label="Female")

        sizer.Add(static_text, flag=wx.ALL | wx.ALIGN_TOP, border=10)
        sizer.Add(male_radio_btn, flag=wx.ALL | wx.ALIGN_TOP, border=10)
        sizer.Add(female_radio_btn, flag=wx.ALL | wx.ALIGN_TOP, border=10)

        self.text_ctrl = wx.TextCtrl(panel)
        sizer.Add(self.text_ctrl, flag=wx.ALL | wx.ALIGN_TOP, border=10)

        male_radio_btn.Bind(wx.EVT_RADIOBUTTON, self.on_radio)
        female_radio_btn.Bind(wx.EVT_RADIOBUTTON, self.on_radio)

        panel.SetSizer(sizer)

    def on_radio(self, event):
        selected_label = event.GetEventObject().GetLabel()
        self.text_ctrl.SetValue(selected_label)


if __name__ == "__main__":
    app = wx.App()
    frame = MyFrame(None, title="wxPython Demo")
    frame.Show()
    app.MainLoop()

3.* 示例:wx.CheckBox

……


3.* 示例:wx.ComboBox

……


3.* 示例:wx.ListBox

……


4 示例

……

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值