21.12.2022 Views

python_para_desenvolvedores_2ed

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Integração com .NET 327

manipulação dos controles. A segunda versão do programa usa herança e

inclui um componente de layout: FlowLayoutPanel.

# -*- coding: utf-8 -*-

"""

Mini calculadora Python

"""

import clr

clr.AddReference('System.Windows.Forms')

clr.AddReference('System.Drawing')

from System.Windows.Forms import *

from System.Drawing import *

class Janela(Form):

"""

Janela principal

"""

def __init__(self):

"""

Inicializa a janela

"""

self.Width=200

self.Height=200

self.Text = 'Mini calculadora Python'

self.lbl = Label(Text='Entre com a expressão:')

self.txt = TextBox()

self.btn = Button(Text='Calcular!')

self.btn.Click += self.on_btn_click

# Layout automático para os controles

self.panel = FlowLayoutPanel(Dock = DockStyle.Fill)

self.panel.Controls.Add(self.lbl)

self.panel.Controls.Add(self.txt)

self.panel.Controls.Add(self.btn)

self.Controls.Add(self.panel)

self.Show()

Application.Run(self)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!