miércoles, 9 de mayo de 2018

Ejemplo de calculadora con librería WX













Código del ejercicio


#!/usr/bin/env python# -*- coding: UTF-8 -*-## generated by wxGlade 0.8.1 on Wed May 09 15:01:56 2018#
import wx

# begin wxGlade: dependencies# end wxGlade
# begin wxGlade: extracode# end wxGlade

class MyFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: MyFrame.__init__        kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.SetSize((400, 300))
        self.text_ctrl_1 = wx.TextCtrl(self, wx.ID_ANY, "")
        self.text_ctrl_2 = wx.TextCtrl(self, wx.ID_ANY, "")
        self.button_2 = wx.Button(self, wx.ID_ANY, "button_2")

        self.__set_properties()
        self.__do_layout()

        self.Bind(wx.EVT_BUTTON, self.SUM, self.button_2)
        # end wxGlade
    def __set_properties(self):
        # begin wxGlade: MyFrame.__set_properties        self.SetTitle("frame")
        # end wxGlade
    def __do_layout(self):
        # begin wxGlade: MyFrame.__do_layout        sizer_1 = wx.FlexGridSizer(3, 2, 0, 0)
        label_2 = wx.StaticText(self, wx.ID_ANY, "label_2")
        sizer_1.Add(label_2, 0, 0, 0)
        sizer_1.Add(self.text_ctrl_1, 0, 0, 0)
        label_3 = wx.StaticText(self, wx.ID_ANY, "label_3")
        sizer_1.Add(label_3, 0, 0, 0)
        sizer_1.Add(self.text_ctrl_2, 0, 0, 0)
        sizer_1.Add(self.button_2, 0, 0, 0)
        sizer_1.Add((0, 0), 0, 0, 0)
        self.SetSizer(sizer_1)
        self.Layout()
        # end wxGlade
    def SUM(self, event):  # wxGlade: MyFrame.<event_handler>        c=int(self.text_ctrl_1.Value)+int(self.text_ctrl_2.Value)
        self.button_2.SetLabel(str(c))
        event.Skip()

# end of class MyFrame
class MyApp(wx.App):
    def OnInit(self):
        self.frame = MyFrame(None, wx.ID_ANY, "")
        self.SetTopWindow(self.frame)
        self.frame.Show()
        return True
# end of class MyApp
if __name__ == "__main__":
    app = MyApp(0)
    app.MainLoop()

No hay comentarios:

Publicar un comentario