wxpython - Enter the IP address

About wxpython input control IP addresses, online resources are relatively small, and easy to find, so the record about ~

#coding=utf-8

import wx
import wx.lib.masked as masked


class MyFrame(wx.Frame):

    def __init__(self, parent, id):
        wx.Frame.__init__(self, parent, id, u'IpAddrCtrl', size = (-1, -1))
        panel = wx.Panel(self) 

        bs_top = wx.BoxSizer(wx.HORIZONTAL)
        bs_center = wx.BoxSizer(wx.HORIZONTAL)

        self.ip_label = wx.StaticText(panel ,wx.ID_ANY,"IP地址")

        self.ip= masked.IpAddrCtrl(panel, wx.ID_ANY)

        bs_top.Add(self.ip_label,proportion=0, flag=wx.ALL, border=5)
        bs_top.Add(self.ip,proportion=0, flag=wx.ALL, border=5)


        self.new_ip_label = wx.StaticText(panel ,wx.ID_ANY,"填写IP:")
        self.new_ip = masked.IpAddrCtrl(panel, wx.ID_ANY)
        self.set_btn = wx.Button(panel,label='设定')
        self.Bind(wx.EVT_BUTTON,self.SetIPButton, self.set_btn)
        
        bs_center.Add(self.new_ip_label,proportion=0, flag=wx.ALL, border=5)
        bs_center.Add(self.new_ip,proportion=0, flag=wx.ALL, border=5)
        bs_center.Add(self.set_btn,proportion=0, flag=wx.ALL, border=5)

        bs_all = wx.BoxSizer(wx.VERTICAL)
        bs_all.Add(bsizer_top,proportion=0, flag=wx.ALL, border=5)
        bs_all.Add(bsizer_center,proportion=0, flag=wx.ALL, border=5)
        
        panel.SetSizer(bs_all)

    def SetIPButton(self,event): 
        self.ip.SetValue(self.new_ip.GetValue())


if __name__ == '__main__':
    app = wx.App()
    frame = MyFrame(None,-1)
    frame.Show()
    frame.Center()
    app.MainLoop()

  Because there is no IP address on the check-box to edit the content, so you can enter any content. (Enter the characters you want to check for compliance, can try wx.Validator usage)

Guess you like

Origin www.cnblogs.com/M-Balance/p/11996371.html