-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp-v7-bitmap_buttons.py
More file actions
107 lines (83 loc) · 3.59 KB
/
app-v7-bitmap_buttons.py
File metadata and controls
107 lines (83 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
"""
Bitmap Buttons
"""
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, title):
super(MyFrame, self).__init__(parent, title=title, size=(600, 500))
self.SetMinSize(wx.Size(500, 400)) # ajusta tamanho minimo da janela
panel = MyPanel(self)
class MyPanel(wx.Panel):
def __init__(self, parent):
super(MyPanel, self).__init__(parent)
vbox = wx.BoxSizer(wx.VERTICAL)
hbox = wx.BoxSizer(wx.HORIZONTAL)
# 1. cria os botoes e adiciona imagem bitmap
# Créditos da imagem: <a href="https://www.flaticon.com/free-icons/copy" title="copy icons">Copy icons created by Catalin Fertu - Flaticon</a>
imageFile1 = 'assets/copy.png'
image1 = wx.Image(imageFile1, wx.BITMAP_TYPE_ANY).Rescale(20, 20).ConvertToBitmap()
self.button1 = wx.BitmapButton(
self,
id=1,
bitmap=image1,
size=(50, 50 # define tamanho e formato do botao
# image1.GetWidth() + 40,
# image1.GetHeight() + 40
)
)
# Créditos da imagem: <a href="https://www.flaticon.com/free-icons/save" title="save icons">Save icons created by Yogi Aprelliyanto - Flaticon</a>
imageFile2 = 'assets/save.png'
image2 = wx.Image(imageFile2, wx.BITMAP_TYPE_ANY).Rescale(25, 25).ConvertToBitmap()
self.button2 = wx.BitmapButton(
self,
# id=-1,
id=2,
bitmap=image2,
size=( # define tamanho e formato do botao
image2.GetWidth() + 100,
image2.GetHeight() + 40
)
)
# Créditos da imagem: <a href="https://www.flaticon.com/free-icons/folder" title="folder icons">Folder icons created by Freepik - Flaticon</a>
imageFile3 = 'assets/folder.png'
image3 = wx.Image(imageFile3, wx.BITMAP_TYPE_ANY).Rescale(32, 32).ConvertToBitmap()
self.button3 = wx.BitmapButton(
self,
# id=-1,
id=3,
bitmap=image3,
size=( # define tamanho e formato do botao
image3.GetWidth() + 40,
image3.GetHeight() + 40
)
)
# 2. define o texto que será exibido nos botões
self.button1.SetLabel('Copy') # label exibido a frente do botao
self.button2.SetLabel('Save')
self.button3.SetLabel('Folder')
self.button1.SetToolTipString("Copy") # passar mouse para mostrar label
self.button2.SetToolTipString("Save")
self.button3.SetToolTipString("Folder")
# 3. adiciona os eventos aos botoes
self.button1.Bind(wx.EVT_BUTTON, self.onClicked)
self.button2.Bind(wx.EVT_BUTTON, self.onClicked)
self.button3.Bind(wx.EVT_BUTTON, self.onClicked)
# 4. organiza os três botões lado a lado no layout horizontal, centralizando cada botao e o hbox é adicionado ao layout vertical vbox, centralizando-o verticalmente
hbox.Add(self.button1, 0, wx.ALIGN_CENTER)
hbox.Add(self.button2, 0, wx.ALIGN_CENTER)
hbox.Add(self.button3, 0, wx.ALIGN_CENTER)
vbox.Add(hbox, 1, wx.ALIGN_CENTER)
self.SetSizer(vbox)
def onClicked(self, event):
""" Mostra no terminal o nome do botao pressionado """
btn = event.GetEventObject().GetLabel()
print('Label of pressed button is:', btn)
class MyApp(wx.App):
def OnInit(self):
title = 'Bitmap Buttons'
self.frame = MyFrame(parent=None, title=title)
self.frame.Show()
return True
if __name__ == '__main__':
app = MyApp()
app.MainLoop()