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.

228 Interface Gráfica

# Associa os métodos com os eventos

wx.EVT_TIMER(self, TIMER_ID, self.on_timer)

wx.EVT_CLOSE(self, self.on_close)

self.Show(True)

def on_timer(self, event):

# Atualiza o relógio

clock = time.asctime().split()[3]

self.control.SetLabel(clock)

def on_close(self, event):

# Para o timer

self.timer.Stop()

self.Destroy()

app = wx.App()

Main(None, wx.ID_ANY, 'Relógio')

app.MainLoop()

Interface:

Exemplo (barra de menus):

# -*- coding: latin1 -*-

import wx

# Identificadores para as opções do menu

ID_FILE_OPEN = wx.NewId()

ID_FILE_SAVE = wx.NewId()

ID_FILE_EXIT = wx.NewId()

ID_HELP_ABOUT = wx.NewId()

class Main(wx.Frame):

def __init__(self, parent, id, title):

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

Saved successfully!

Ooh no, something went wrong!