惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Attack and Defense Labs
Attack and Defense Labs
The GitHub Blog
The GitHub Blog
C
Check Point Blog
博客园_首页
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
F
Full Disclosure
Microsoft Security Blog
Microsoft Security Blog
爱范儿
爱范儿
Recent Announcements
Recent Announcements
阮一峰的网络日志
阮一峰的网络日志
G
GRAHAM CLULEY
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Threat Research - Cisco Blogs
C
Cybersecurity and Infrastructure Security Agency CISA
V
Vulnerabilities – Threatpost
K
Kaspersky official blog
博客园 - 司徒正美
S
Schneier on Security
T
The Exploit Database - CXSecurity.com
Project Zero
Project Zero
云风的 BLOG
云风的 BLOG
Cisco Talos Blog
Cisco Talos Blog
Know Your Adversary
Know Your Adversary
雷峰网
雷峰网
V
V2EX - 技术
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Spread Privacy
Spread Privacy
罗磊的独立博客
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Security Affairs
SecWiki News
SecWiki News
Schneier on Security
Schneier on Security
O
OpenAI News
Jina AI
Jina AI
PCI Perspectives
PCI Perspectives
Cyberwarzone
Cyberwarzone
Y
Y Combinator Blog
Apple Machine Learning Research
Apple Machine Learning Research
B
Blog RSS Feed
I
InfoQ
D
Docker
P
Palo Alto Networks Blog
Recorded Future
Recorded Future
M
MIT News - Artificial intelligence
博客园 - Franky
B
Blog
Scott Helme
Scott Helme
博客园 - 叶小钗
D
DataBreaches.Net

博客园 - 许明会

异步编程,采用WorkgroupWorker,async和await关键字 OCR图像识别技术-Asprise OCR 关于委托,事件和类的设计准则 JavaScript能干什么? C#泛型代理、泛型接口、泛型类型、泛型方法 Delegate, Method as Parameter. DES对称性加密 利用委托实现异步调用 通过Windows组策略限制证书组织流氓软件的安装运行 枚举\位域\结构综合实验 - 许明会 - 博客园 public static void Invoke (Action action) C#编写WIN32系统托盘程序 C#的互操作性:缓冲区、结构、指针 SQLServer异步调用,批量复制 Python体验(09)-图形界面之Pannel和Sizer Python体验(08)-图形界面之工具栏和状态栏 Python体验(07)-图形界面之菜单 C#利用WIN32实现按键注册 Javascript猜数字游戏
Python体验(10)-图形界面之计算器
许明会 · 2016-03-21 · via 博客园 - 许明会
  1 import wx
  2 class Form(wx.Frame):
  3     def __init__( self, parent, id, title ):
  4         wx.Frame.__init__(self,parent,id,title,wx.DefaultPosition,wx.Size(300, 250))
  5         self.formula = False
  6         menuBar = wx.MenuBar()
  7         mnuFile = wx.Menu()
  8         mnuFile.Append( 22, '&Quit', 'Exit Calculator' )
  9         menuBar.Append( mnuFile, '&File' )
 10         wx.EVT_MENU( self, 22, self.OnClose )
 11         self.SetMenuBar( menuBar )
 12 
 13         self.display = wx.TextCtrl(self, -1, '', style=wx.TE_RIGHT)
 14         gs = wx.GridSizer(5, 4, 3, 3)
 15         gs.AddMany(
 16             [
 17                 (wx.Button(self, 12, '-'), 0, wx.EXPAND),
 18                 (wx.Button(self, 20, 'Cls'), 0, wx.EXPAND),
 19                 (wx.Button(self, 21, 'Bck'), 0, wx.EXPAND),
 20                 (wx.StaticText(self, -1, ''), 0, wx.EXPAND),
 21                 (wx.Button(self, 22, 'Close'), 0, wx.EXPAND),
 22                 (wx.Button(self, 1, '7'), 0, wx.EXPAND),
 23                 (wx.Button(self, 2, '8'), 0, wx.EXPAND),
 24                 (wx.Button(self, 3, '9'), 0, wx.EXPAND),
 25                 (wx.Button(self, 4, '/'), 0, wx.EXPAND),
 26                 (wx.Button(self, 5, '4'), 0, wx.EXPAND),
 27                 (wx.Button(self, 6, '5'), 0, wx.EXPAND),
 28                 (wx.Button(self, 7, '6'), 0, wx.EXPAND),
 29                 (wx.Button(self, 8, '*'), 0, wx.EXPAND),
 30                 (wx.Button(self, 10, '2'), 0, wx.EXPAND),
 31                 (wx.Button(self, 11, '3'), 0, wx.EXPAND),
 32                 (wx.Button(self, 9, '1'), 0, wx.EXPAND),
 33                 (wx.Button(self, 16, '+'), 0, wx.EXPAND),
 34                 (wx.Button(self, 15, '='), 0, wx.EXPAND),
 35                 (wx.Button(self, 14, '.'), 0, wx.EXPAND),
 36                 (wx.Button(self, 13, '0'), 0, wx.EXPAND)
 37             ]
 38         )
 39         sizer = wx.BoxSizer( wx.VERTICAL )
 40         sizer.Add(self.display, 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 4)
 41         sizer.Add(gs, 1, wx.EXPAND)
 42         self.SetSizer(sizer)
 43         self.Centre()
 44 
 45         wx.EVT_BUTTON(self, 20, self.OnClear)
 46         wx.EVT_BUTTON(self, 21, self.OnBackspace)
 47         wx.EVT_BUTTON(self, 22, self.OnClose)
 48         wx.EVT_BUTTON(self, 1, self.OnNumber)
 49         wx.EVT_BUTTON(self, 2, self.OnNumber)
 50         wx.EVT_BUTTON(self, 3, self.OnNumber)
 51         wx.EVT_BUTTON(self, 4, self.OnFormula)
 52         wx.EVT_BUTTON(self, 5, self.OnNumber)
 53         wx.EVT_BUTTON(self, 6, self.OnNumber)
 54         wx.EVT_BUTTON(self, 7, self.OnNumber)
 55         wx.EVT_BUTTON(self, 8, self.OnFormula)
 56         wx.EVT_BUTTON(self, 9, self.OnNumber)
 57         wx.EVT_BUTTON(self, 10, self.OnNumber)
 58         wx.EVT_BUTTON(self, 11, self.OnNumber)
 59         wx.EVT_BUTTON(self, 12, self.OnFormula)
 60         wx.EVT_BUTTON(self, 13, self.OnNumber)
 61         wx.EVT_BUTTON(self, 14, self.OnFormula)
 62         wx.EVT_BUTTON(self, 15, self.OnEqual)
 63         wx.EVT_BUTTON(self, 16, self.OnFormula)
 64 
 65     def OnClear(self, event):
 66         self.display.Clear()
 67     def OnBackspace(self, event):
 68         formula = self.display.GetValue()
 69         self.display.Clear()
 70         self.display.SetValue(formula[:-1])
 71     def OnClose(self, event):
 72         self.Close()
 73     def OnEqual(self,event):
 74         if self.formula:
 75             return
 76         formula = self.display.GetValue()
 77         self.formula = True
 78         try:
 79             self.display.Clear()
 80             output = eval(formula)
 81             self.display.AppendText(str(output))
 82         except StandardError:
 83             self.display.AppendText("Error")
 84 
 85     def OnFormula(self,event):
 86         if self.formula:
 87             return
 88         self.display.AppendText(event.EventObject.LabelText)
 89 
 90     def OnNumber(self,event):
 91         if self.formula:
 92             self.display.Clear()
 93             self.formula=False
 94         self.display.AppendText(event.EventObject.LabelText)
 95 
 96 class MyApp(wx.App):
 97     def OnInit(self):
 98         frame = Form(None, -1, "Phoenix Caculator")
 99         frame.Show(True)
100         self.SetTopWindow(frame)
101         return True
102 
103 app = MyApp(0)
104 app.MainLoop()
import wx
class Form(wx.Frame):
    def __init__( self, parent, id, title ):
        wx.Frame.__init__(self,parent,id,title,wx.DefaultPosition,wx.Size(300, 250))
        self.formula = False
        menuBar = wx.MenuBar()
        mnuFile = wx.Menu()
        mnuFile.Append( 22, '&Quit', 'Exit Calculator' )
        menuBar.Append( mnuFile, '&File' )
        wx.EVT_MENU( self, 22, self.OnClose )
        self.SetMenuBar( menuBar )

        self.display = wx.TextCtrl(self, -1, '', style=wx.TE_RIGHT)
        gs = wx.GridSizer(5, 4, 3, 3)
        gs.AddMany(
            [
                (wx.Button(self, 12, '-'), 0, wx.EXPAND),
                (wx.Button(self, 20, 'Cls'), 0, wx.EXPAND),
                (wx.Button(self, 21, 'Bck'), 0, wx.EXPAND),
                (wx.StaticText(self, -1, ''), 0, wx.EXPAND),
                (wx.Button(self, 22, 'Close'), 0, wx.EXPAND),
                (wx.Button(self, 1, '7'), 0, wx.EXPAND),
                (wx.Button(self, 2, '8'), 0, wx.EXPAND),
                (wx.Button(self, 3, '9'), 0, wx.EXPAND),
                (wx.Button(self, 4, '/'), 0, wx.EXPAND),
                (wx.Button(self, 5, '4'), 0, wx.EXPAND),
                (wx.Button(self, 6, '5'), 0, wx.EXPAND),
                (wx.Button(self, 7, '6'), 0, wx.EXPAND),
                (wx.Button(self, 8, '*'), 0, wx.EXPAND),
                (wx.Button(self, 10, '2'), 0, wx.EXPAND),
                (wx.Button(self, 11, '3'), 0, wx.EXPAND),
                (wx.Button(self, 9, '1'), 0, wx.EXPAND),
                (wx.Button(self, 16, '+'), 0, wx.EXPAND),
                (wx.Button(self, 15, '='), 0, wx.EXPAND),
                (wx.Button(self, 14, '.'), 0, wx.EXPAND),
                (wx.Button(self, 13, '0'), 0, wx.EXPAND)
            ]
        )
        sizer = wx.BoxSizer( wx.VERTICAL )
        sizer.Add(self.display, 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 4)
        sizer.Add(gs, 1, wx.EXPAND)
        self.SetSizer(sizer)
        self.Centre()

        wx.EVT_BUTTON(self, 20, self.OnClear)
        wx.EVT_BUTTON(self, 21, self.OnBackspace)
        wx.EVT_BUTTON(self, 22, self.OnClose)
        wx.EVT_BUTTON(self, 1, self.OnNumber)
        wx.EVT_BUTTON(self, 2, self.OnNumber)
        wx.EVT_BUTTON(self, 3, self.OnNumber)
        wx.EVT_BUTTON(self, 4, self.OnFormula)
        wx.EVT_BUTTON(self, 5, self.OnNumber)
        wx.EVT_BUTTON(self, 6, self.OnNumber)
        wx.EVT_BUTTON(self, 7, self.OnNumber)
        wx.EVT_BUTTON(self, 8, self.OnFormula)
        wx.EVT_BUTTON(self, 9, self.OnNumber)
        wx.EVT_BUTTON(self, 10, self.OnNumber)
        wx.EVT_BUTTON(self, 11, self.OnNumber)
        wx.EVT_BUTTON(self, 12, self.OnFormula)
        wx.EVT_BUTTON(self, 13, self.OnNumber)
        wx.EVT_BUTTON(self, 14, self.OnFormula)
        wx.EVT_BUTTON(self, 15, self.OnEqual)
        wx.EVT_BUTTON(self, 16, self.OnFormula)

    def OnClear(self, event):
        self.display.Clear()
    def OnBackspace(self, event):
        formula = self.display.GetValue()
        self.display.Clear()
        self.display.SetValue(formula[:-1])
    def OnClose(self, event):
        self.Close()
    def OnEqual(self,event):
        if self.formula:
            return
        formula = self.display.GetValue()
        self.formula = True
        try:
            self.display.Clear()
            output = eval(formula)
            self.display.AppendText(str(output))
        except StandardError:
            self.display.AppendText("Error")

    def OnFormula(self,event):
        if self.formula:
            return
        self.display.AppendText(event.EventObject.LabelText)

    def OnNumber(self,event):
        if self.formula:
            self.display.Clear()
            self.formula=False
        self.display.AppendText(event.EventObject.LabelText)

class MyApp(wx.App):
    def OnInit(self):
        frame = Form(None, -1, "Phoenix Caculator")
        frame.Show(True)
        self.SetTopWindow(frame)
        return True

app = MyApp(0)
app.MainLoop()