Skip to content

Commit 2d38a72

Browse files
author
Jan Bodnar
committed
first commit
0 parents  commit 2d38a72

23 files changed

+650
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cairo
2+
doc

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
wxPython code examples
2+
3+
http://zetcode.com/wxpython/

graphics/draw_line.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
"""
5+
ZetCode wxPython tutorial
6+
7+
This program draws a line on the
8+
frame window after a while.
9+
10+
author: Jan Bodnar
11+
website: zetcode.com
12+
last edited: April 28 2018
13+
"""
14+
15+
import wx
16+
17+
class Example(wx.Frame):
18+
19+
def __init__(self, parent, title):
20+
super(Example, self).__init__(parent, title=title,
21+
size=(350, 250))
22+
23+
wx.CallLater(2000, self.DrawLine)
24+
25+
self.Centre()
26+
27+
def DrawLine(self):
28+
dc = wx.ClientDC(self)
29+
dc.DrawLine(50, 60, 190, 60)
30+
31+
if __name__ == '__main__':
32+
33+
app = wx.App()
34+
ex = Example(None, 'Line')
35+
ex.Show()
36+
app.MainLoop()

intro/centering.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
# centering.py
5+
6+
import wx
7+
8+
class Example(wx.Frame):
9+
10+
def __init__(self, parent, title):
11+
super(Example, self).__init__(parent, title=title,
12+
size=(300, 200))
13+
14+
self.Centre()
15+
16+
def main():
17+
18+
app = wx.App()
19+
ex = Example(None, title='Centering')
20+
ex.Show()
21+
app.MainLoop()
22+
23+
if __name__ == '__main__':
24+
main()

intro/moving.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
# moving.py
5+
6+
import wx
7+
8+
class Example(wx.Frame):
9+
10+
def __init__(self, parent, title):
11+
super(Example, self).__init__(parent, title=title,
12+
size=(300, 200))
13+
14+
self.Move((800, 250))
15+
16+
def main():
17+
18+
app = wx.App()
19+
ex = Example(None, title='Moving')
20+
ex.Show()
21+
app.MainLoop()
22+
23+
if __name__ == '__main__':
24+
main()

intro/no_minimize.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
# no_minimizebox.py
5+
6+
import wx
7+
8+
app = wx.App()
9+
frame = wx.Frame(None, style=wx.MAXIMIZE_BOX | wx.RESIZE_BORDER
10+
| wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX)
11+
frame.Show(True)
12+
13+
app.MainLoop()

intro/set_size.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
# set_size.py
5+
6+
import wx
7+
8+
class Example(wx.Frame):
9+
10+
def __init__(self, parent, title):
11+
super(Example, self).__init__(parent, title=title,
12+
size=(350, 250))
13+
14+
def main():
15+
16+
app = wx.App()
17+
ex = Example(None, title='Sizing')
18+
ex.Show()
19+
app.MainLoop()
20+
21+
22+
if __name__ == '__main__':
23+
main()

intro/simple.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
# simple.py
5+
6+
import wx
7+
8+
app = wx.App()
9+
10+
frame = wx.Frame(None, title='Simple application')
11+
frame.Show()
12+
13+
app.MainLoop()

menus/checkmenu_item.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
"""
5+
ZetCode wxPython tutorial
6+
7+
This example creates a checked
8+
menu item.
9+
10+
author: Jan Bodnar
11+
website: www.zetcode.com
12+
last modified: April 2018
13+
"""
14+
15+
import wx
16+
17+
18+
class Example(wx.Frame):
19+
20+
def __init__(self, *args, **kwargs):
21+
super(Example, self).__init__(*args, **kwargs)
22+
23+
self.InitUI()
24+
25+
def InitUI(self):
26+
27+
menubar = wx.MenuBar()
28+
viewMenu = wx.Menu()
29+
30+
self.shst = viewMenu.Append(wx.ID_ANY, 'Show statusbar',
31+
'Show Statusbar', kind=wx.ITEM_CHECK)
32+
self.shtl = viewMenu.Append(wx.ID_ANY, 'Show toolbar',
33+
'Show Toolbar', kind=wx.ITEM_CHECK)
34+
35+
viewMenu.Check(self.shst.GetId(), True)
36+
viewMenu.Check(self.shtl.GetId(), True)
37+
38+
self.Bind(wx.EVT_MENU, self.ToggleStatusBar, self.shst)
39+
self.Bind(wx.EVT_MENU, self.ToggleToolBar, self.shtl)
40+
41+
menubar.Append(viewMenu, '&View')
42+
self.SetMenuBar(menubar)
43+
44+
self.toolbar = self.CreateToolBar()
45+
self.toolbar.AddTool(1, '', wx.Bitmap('texit.png'))
46+
self.toolbar.Realize()
47+
48+
self.statusbar = self.CreateStatusBar()
49+
self.statusbar.SetStatusText('Ready')
50+
51+
self.SetSize((450, 350))
52+
self.SetTitle('Check menu item')
53+
self.Centre()
54+
55+
56+
def ToggleStatusBar(self, e):
57+
58+
if self.shst.IsChecked():
59+
self.statusbar.Show()
60+
else:
61+
self.statusbar.Hide()
62+
63+
def ToggleToolBar(self, e):
64+
65+
if self.shtl.IsChecked():
66+
self.toolbar.Show()
67+
else:
68+
self.toolbar.Hide()
69+
70+
71+
def main():
72+
73+
app = wx.App()
74+
ex = Example(None)
75+
ex.Show()
76+
app.MainLoop()
77+
78+
79+
if __name__ == '__main__':
80+
main()

menus/context_menu.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
"""
5+
ZetCode wxPython tutorial
6+
7+
In this example, we create a context menu.
8+
9+
author: Jan Bodnar
10+
website: www.zetcode.com
11+
last modified: April 2018
12+
"""
13+
14+
import wx
15+
16+
class MyPopupMenu(wx.Menu):
17+
18+
def __init__(self, parent):
19+
super(MyPopupMenu, self).__init__()
20+
21+
self.parent = parent
22+
23+
mmi = wx.MenuItem(self, wx.NewId(), 'Minimize')
24+
self.Append(mmi)
25+
self.Bind(wx.EVT_MENU, self.OnMinimize, mmi)
26+
27+
cmi = wx.MenuItem(self, wx.NewId(), 'Close')
28+
self.Append(cmi)
29+
self.Bind(wx.EVT_MENU, self.OnClose, cmi)
30+
31+
32+
def OnMinimize(self, e):
33+
self.parent.Iconize()
34+
35+
def OnClose(self, e):
36+
self.parent.Close()
37+
38+
39+
class Example(wx.Frame):
40+
41+
def __init__(self, *args, **kwargs):
42+
super(Example, self).__init__(*args, **kwargs)
43+
44+
self.InitUI()
45+
46+
def InitUI(self):
47+
48+
self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
49+
50+
self.SetSize((350, 250))
51+
self.SetTitle('Context menu')
52+
self.Centre()
53+
54+
def OnRightDown(self, e):
55+
self.PopupMenu(MyPopupMenu(self), e.GetPosition())
56+
57+
58+
def main():
59+
60+
app = wx.App()
61+
ex = Example(None)
62+
ex.Show()
63+
app.MainLoop()
64+
65+
66+
if __name__ == '__main__':
67+
main()

0 commit comments

Comments
 (0)