أهلا بك يا إبراهيم.
من خلال هذا المثال يمكنك إنشاء dialog box لإدخال 3 أرقام أو أحرف لتفعيل رمز الـ PIN.
import wx
class PinDialog(wx.Dialog):
def __init__(self, parent, title):
wx.Dialog.__init__(self, parent, title=title)
self.pin = ""
# create the text entry boxes
self.pin_textctrl1 = wx.TextCtrl(self, style=wx.TE_PASSWORD)
self.pin_textctrl2 = wx.TextCtrl(self, style=wx.TE_PASSWORD)
self.pin_textctrl3 = wx.TextCtrl(self, style=wx.TE_PASSWORD)
# create the OK and Cancel buttons
self.ok_button = wx.Button(self, label="OK")
self.cancel_button = wx.Button(self, label="Cancel")
# bind the buttons to their event handlers
self.ok_button.Bind(wx.EVT_BUTTON, self.on_ok)
self.cancel_button.Bind(wx.EVT_BUTTON, self.on_cancel)
# create a sizer to layout the widgets
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(wx.StaticText(self, label="Enter your PIN:"), flag=wx.CENTER|wx.TOP, border=10)
sizer.Add(wx.StaticLine(self), flag=wx.EXPAND|wx.TOP|wx.BOTTOM, border=10)
sizer.Add(self.pin_textctrl1, flag=wx.CENTER|wx.ALL, border=5)
sizer.Add(self.pin_textctrl2, flag=wx.CENTER|wx.ALL, border=5)
sizer.Add(self.pin_textctrl3, flag=wx.CENTER|wx.ALL, border=5)
sizer.Add(wx.StaticLine(self), flag=wx.EXPAND|wx.TOP|wx.BOTTOM, border=10)
button_sizer = wx.BoxSizer(wx.HORIZONTAL)
button_sizer.Add(self.ok_button, flag=wx.CENTER|wx.ALL, border=5)
button_sizer.Add(self.cancel_button, flag=wx.CENTER|wx.ALL, border=5)
sizer.Add(button_sizer, flag=wx.CENTER|wx.ALL, border=10)
self.SetSizer(sizer)
sizer.Fit(self)
def on_ok(self, event):
# get the values from the text entry boxes
self.pin = self.pin_textctrl1.GetValue() + self.pin_textctrl2.GetValue() + self.pin_textctrl3.GetValue()
self.EndModal(wx.ID_OK)
def on_cancel(self, event):
self.EndModal(wx.ID_CANCEL)
def get_pin(self):
return self.pin
# create the wx.App object
app = wx.App()
# create the main window
frame = wx.Frame(None, title="Pin Dialog")
# create the dialog box and show it
pin_dialog = PinDialog(frame, "Enter Your PIN")
result = pin_dialog.ShowModal()
# get the PIN value and print it to the console
if result == wx.ID_OK:
pin = pin_dialog.get_pin()
print("PIN entered:", pin)
# clean up
pin_dialog.Destroy()
frame.Destroy()
# start the main event loop
app.MainLoop()