- GUI
- Windows API tutorial
- Introduction to Windows API
- Windows API main functions
- System functions in Windows API
- Strings in Windows API
- Date & time in Windows API
- A window in Windows API
- First steps in UI
- Windows API menus
- Windows API dialogs
- Windows API controls I
- Windows API controls II
- Windows API controls III
- Advanced controls in Windows API
- Custom controls in Windows API
- The GDI in Windows API
- PyQt4 tutorial
- PyQt5 tutorial
- Qt4 tutorial
- Introduction to Qt4 toolkit
- Qt4 utility classes
- Strings in Qt4
- Date and time in Qt4
- Working with files and directories in Qt4
- First programs in Qt4
- Menus and toolbars in Qt4
- Layout management in Qt4
- Events and signals in Qt4
- Qt4 Widgets
- Qt4 Widgets II
- Painting in Qt4
- Custom widget in Qt4
- The Breakout game in Qt4
- Qt5 tutorial
- Introduction to Qt5 toolkit
- Strings in Qt5
- Date and time in Qt5
- Containers in Qt5
- Working with files and directories in Qt5
- First programs in Qt5
- Menus and toolbars in Qt5
- Layout management in Qt5
- Events and signals in Qt5
- Qt5 Widgets
- Qt5 Widgets II
- Painting in Qt5
- Custom widget in Qt5
- Snake in Qt5
- The Breakout game in Qt5
- PySide tutorial
- Tkinter tutorial
- Tcl/Tk tutorial
- Qt Quick tutorial
- Java Swing tutorial
- JavaFX tutorial
- Java SWT tutorial
- wxWidgets tutorial
- Introduction to wxWidgets
- wxWidgets helper classes
- First programs in wxWidgets
- Menus and toolbars in wxWidgets
- Layout management in wxWidgets
- Events in wxWidgets
- Dialogs in wxWidgets
- wxWidgets widgets
- wxWidgets widgets II
- Drag and Drop in wxWidgets
- Device Contexts in wxWidgets
- Custom widgets in wxWidgets
- The Tetris game in wxWidgets
- wxPython tutorial
- Introduction to wxPython
- First Steps
- Menus and toolbars
- Layout management in wxPython
- Events in wxPython
- wxPython dialogs
- Widgets
- Advanced widgets in wxPython
- Drag and drop in wxPython
- Internationalisation
- Application skeletons in wxPython
- The GDI
- Mapping modes
- Creating custom widgets
- Tips and Tricks
- wxPython Gripts
- The Tetris game in wxPython
- C# Winforms Mono tutorial
- Java Gnome tutorial
- Introduction to Java Gnome
- First steps in Java Gnome
- Layout management in Java Gnome
- Layout management II in Java Gnome
- Menus in Java Gnome
- Toolbars in Java Gnome
- Events in Java Gnome
- Widgets in Java Gnome
- Widgets II in Java Gnome
- Advanced widgets in Java Gnome
- Dialogs in Java Gnome
- Pango in Java Gnome
- Drawing with Cairo in Java Gnome
- Drawing with Cairo II
- Nibbles in Java Gnome
- QtJambi tutorial
- GTK+ tutorial
- Ruby GTK tutorial
- GTK# tutorial
- Visual Basic GTK# tutorial
- PyGTK tutorial
- Introduction to PyGTK
- First steps in PyGTK
- Layout management in PyGTK
- Menus in PyGTK
- Toolbars in PyGTK
- Signals & events in PyGTK
- Widgets in PyGTK
- Widgets II in PyGTK
- Advanced widgets in PyGTK
- Dialogs in PyGTK
- Pango
- Pango II
- Drawing with Cairo in PyGTK
- Drawing with Cairo II
- Snake game in PyGTK
- Custom widget in PyGTK
- PHP GTK tutorial
- C# Qyoto tutorial
- Ruby Qt tutorial
- Visual Basic Qyoto tutorial
- Mono IronPython Winforms tutorial
- Introduction
- First steps in IronPython Mono Winforms
- Layout management
- Menus and toolbars
- Basic Controls in Mono Winforms
- Basic Controls II in Mono Winforms
- Advanced Controls in Mono Winforms
- Dialogs
- Drag & drop in Mono Winforms
- Painting
- Painting II in IronPython Mono Winforms
- Snake in IronPython Mono Winforms
- The Tetris game in IronPython Mono Winforms
- FreeBASIC GTK tutorial
- Jython Swing tutorial
- JRuby Swing tutorial
- Visual Basic Winforms tutorial
- JavaScript GTK tutorial
- Ruby HTTPClient tutorial
- Ruby Faraday tutorial
- Ruby Net::HTTP tutorial
- Java 2D games tutorial
- Java 2D tutorial
- Cairo graphics tutorial
- PyCairo tutorial
- HTML5 canvas tutorial
- Python tutorial
- Python language
- Interactive Python
- Python lexical structure
- Python data types
- Strings in Python
- Python lists
- Python dictionaries
- Python operators
- Keywords in Python
- Functions in Python
- Files in Python
- Object-oriented programming in Python
- Modules
- Packages in Python
- Exceptions in Python
- Iterators and Generators
- Introspection in Python
- Ruby tutorial
- PHP tutorial
- Visual Basic tutorial
- Visual Basic
- Visual Basic lexical structure
- Basics
- Visual Basic data types
- Strings in Visual Basic
- Operators
- Flow control
- Visual Basic arrays
- Procedures & functions in Visual Basic
- Organizing code in Visual Basic
- Object-oriented programming
- Object-oriented programming II in Visual Basic
- Collections in Visual Basic
- Input & output
- Tcl tutorial
- C# tutorial
- Java tutorial
- AWK tutorial
- Jetty tutorial
- Tomcat Derby tutorial
- Jtwig tutorial
- Android tutorial
- Introduction to Android development
- First Android application
- Android Button widgets
- Android Intents
- Layout management in Android
- Android Spinner widget
- SeekBar widget
- Android ProgressBar widget
- Android ListView widget
- Android Pickers
- Android menus
- Dialogs
- Drawing in Android
- Java EE 5 tutorials
- Introduction
- Installing Java
- Installing NetBeans 6
- Java Application Servers
- Resin CGIServlet
- JavaServer Pages, (JSPs)
- Implicit objects in JSPs
- Shopping cart
- JSP & MySQL Database
- Java Servlets
- Sending email in a Servlet
- Creating a captcha in a Servlet
- DataSource & DriverManager
- Java Beans
- Custom JSP tags
- Object relational mapping with iBATIS
- Jsoup tutorial
- MySQL tutorial
- MySQL quick tutorial
- MySQL storage engines
- MySQL data types
- Creating, altering and dropping tables in MySQL
- MySQL expressions
- Inserting, updating, and deleting data in MySQL
- The SELECT statement in MySQL
- MySQL subqueries
- MySQL constraints
- Exporting and importing data in MySQL
- Joining tables in MySQL
- MySQL functions
- Views in MySQL
- Transactions in MySQL
- MySQL stored routines
- MySQL Python tutorial
- MySQL Perl tutorial
- MySQL C API programming tutorial
- MySQL Visual Basic tutorial
- MySQL PHP tutorial
- MySQL Java tutorial
- MySQL Ruby tutorial
- MySQL C# tutorial
- SQLite tutorial
- SQLite C tutorial
- SQLite PHP tutorial
- SQLite Python tutorial
- SQLite Perl tutorial
- SQLite Ruby tutorial
- SQLite C# tutorial
- SQLite Visual Basic tutorial
- PostgreSQL C tutorial
- PostgreSQL Python tutorial
- PostgreSQL Ruby tutorial
- PostgreSQL PHP tutorial
- PostgreSQL Java tutorial
- Apache Derby tutorial
- SQLAlchemy tutorial
- MongoDB PHP tutorial
- MongoDB Java tutorial
- MongoDB JavaScript tutorial
- MongoDB Ruby tutorial
- Spring JdbcTemplate tutorial
- JDBI tutorial
Tips and Tricks
In this section we will show various interesting tips in wxPython. Here we will see examples that could not be put elsewhere.
Interactive Button
When we enter the area of the button widget with a mouse pointer, wx.EVT_ENTER_WINDOW
event is generated. Similarly, wx.EVT_LEAVE_WINDOW
event is generated, when we leave the area of the widget. We bind two methods to these events.
#!/usr/bin/python # -*- coding: utf-8 -*- ''' ZetCode wxPython tutorial This example shows an interactive button. author: Jan Bodnar website: www.zetcode.com last modified: September 2011 ''' import wx from wx.lib.buttons import GenButton class Example(wx.Frame): def __init__(self, *args, **kwargs): super(Example, self).__init__(*args, **kwargs) self.InitUI() def InitUI(self): panel = wx.Panel(self) btn = GenButton(panel, label='Button', pos=(100, 100)) btn.SetBezelWidth(1) btn.SetBackgroundColour('DARKGREY') wx.EVT_ENTER_WINDOW(btn, self.OnEnter) wx.EVT_LEAVE_WINDOW(btn, self.OnLeave) self.SetSize((300, 200)) self.SetTitle('Interactive button') self.Centre() self.Show(True) def OnEnter(self, e): btn = e.GetEventObject() btn.SetBackgroundColour('GREY79') btn.Refresh() def OnLeave(self, e): btn = e.GetEventObject() btn.SetBackgroundColour('DARKGREY') btn.Refresh() def main(): ex = wx.App() Example(None) ex.MainLoop() if __name__ == '__main__': main()
We have used a GenButton
instead of a basic wx.Button
.
from wx.lib.buttons import GenButton
The GenButton
is located in the wx.lib.buttons
module.
btn.SetBezelWidth(1)
The SetBezelWidth()
method creates some 3D effect on the button.
def OnEnter(self, e): btn = e.GetEventObject() btn.SetBackgroundColour('GREY79') btn.Refresh()
In reaction to the wx.EVT_ENTER_WINDOW
, we change the background colour of the button.
Isabelle
When an error occurs in an application, an error dialog usually appears. This might get annoying. I have noticed a better solution in a SAP system. When a user enters an invalid command, statusbar turns red and an error message is displayed on stausbar. The red colour catches the eye and the user can easily read the error message. The following code mimics this situation.
#!/usr/bin/python # Isabelle import wx ID_TIMER = 1 ID_EXIT = 2 ID_ABOUT = 3 ID_BUTTON = 4 class Isabelle(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title) self.timer = wx.Timer(self, ID_TIMER) self.blick = 0 file = wx.Menu() file.Append(ID_EXIT, '&Quit\tCtrl+Q', 'Quit Isabelle') help = wx.Menu() help.Append(ID_ABOUT, '&About', 'O Programe') menubar = wx.MenuBar() menubar.Append(file, '&File') menubar.Append(help, '&Help') self.SetMenuBar(menubar) toolbar = wx.ToolBar(self, -1) self.tc = wx.TextCtrl(toolbar, -1, size=(100, -1)) btn = wx.Button(toolbar, ID_BUTTON, 'Ok', size=(40, 28)) toolbar.AddControl(self.tc) toolbar.AddSeparator() toolbar.AddControl(btn) toolbar.Realize() self.SetToolBar(toolbar) self.Bind(wx.EVT_BUTTON, self.OnLaunchCommandOk, id=ID_BUTTON) self.Bind(wx.EVT_MENU, self.OnAbout, id=ID_ABOUT) self.Bind(wx.EVT_MENU, self.OnExit, id=ID_EXIT) self.Bind(wx.EVT_TIMER, self.OnTimer, id=ID_TIMER) self.panel = wx.Panel(self, -1, (0, 0), (500 , 300)) self.panel.SetBackgroundColour('GRAY') self.sizer=wx.BoxSizer(wx.VERTICAL) self.sizer.Add(self.panel, 1, wx.EXPAND) self.SetSizer(self.sizer) self.statusbar = self.CreateStatusBar() self.statusbar.SetStatusText('Welcome to Isabelle') self.Centre() self.Show(True) def OnExit(self, event): dlg = wx.MessageDialog(self, 'Are you sure to quit Isabelle?', 'Please Confirm', wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION) if dlg.ShowModal() == wx.ID_YES: self.Close(True) def OnAbout(self, event): dlg = wx.MessageDialog(self, 'Isabelle\t\n' '2004\t', 'About', wx.OK | wx.ICON_INFORMATION) dlg.ShowModal() dlg.Destroy() def OnLaunchCommandOk(self, event): input = self.tc.GetValue() if input == '/bye': self.OnExit(self) elif input == '/about': self.OnAbout(self) elif input == '/bell': wx.Bell() else: self.statusbar.SetBackgroundColour('RED') self.statusbar.SetStatusText('Unknown Command') self.statusbar.Refresh() self.timer.Start(50) self.tc.Clear() def OnTimer(self, event): self.blick = self.blick + 1 if self.blick == 25: self.statusbar.SetBackgroundColour('#E0E2EB') self.statusbar.Refresh() self.timer.Stop() self.blick = 0 app = wx.App() Isabelle(None, -1, 'Isabelle') app.MainLoop()
There is a wx.TextCtrl
on the Statusbar. There you enter your commands. We have defined three commands: /bye, /about, and /beep. If you mistype any of them, Statusbar turns red and displays an error. This is done with the wx.Timer
class.

Undo/Redo framework
Many applications have the ability to undo and redo the user's actions. The following example shows how it can be accomplished in wxPython.

#!/usr/bin/python # undoredo.py from wx.lib.sheet import * import wx stockUndo = [] stockRedo = [] ID_QUIT = 10 ID_UNDO = 11 ID_REDO = 12 ID_EXIT = 13 ID_COLSIZE = 80 ID_ROWSIZE = 20 class UndoText: def __init__(self, sheet, text1, text2, row, column): self.RedoText = text2 self.row = row self.col = column self.UndoText = text1 self.sheet = sheet def undo(self): self.RedoText = self.sheet.GetCellValue(self.row, self.col) if self.UndoText == None: self.sheetSetCellValue('') else: self.sheet.SetCellValue(self.row, self.col, self.UndoText) def redo(self): if self.RedoText == None: self.sheet.SetCellValue('') else: self.sheet.SetCellValue(self.row, self.col, self.RedoText) class UndoColSize: def __init__(self, sheet, position, size): self.sheet = sheet self.pos = position self.RedoSize = size self.UndoSize = ID_COLSIZE def undo(self): self.RedoSize = self.sheet.GetColSize(self.pos) self.sheet.SetColSize(self.pos, self.UndoSize) self.sheet.ForceRefresh() def redo(self): self.UndoSize = ID_COLSIZE self.sheet.SetColSize(self.pos, self.RedoSize) self.sheet.ForceRefresh() class UndoRowSize: def __init__(self, sheet, position, size): self.sheet = sheet self.pos = position self.RedoSize = size self.UndoSize = ID_ROWSIZE def undo(self): self.RedoSize = self.sheet.GetRowSize(self.pos) self.sheet.SetRowSize(self.pos, self.UndoSize) self.sheet.ForceRefresh() def redo(self): self.UndoSize = ID_ROWSIZE self.sheet.SetRowSize(self.pos, self.RedoSize) self.sheet.ForceRefresh() class MySheet(CSheet): instance = 0 def __init__(self, parent): CSheet.__init__(self, parent) self.SetRowLabelAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE) self.text = '' def OnCellChange(self, event): toolbar = self.GetParent().toolbar if (toolbar.GetToolEnabled(ID_UNDO) == False): toolbar.EnableTool(ID_UNDO, True) r = event.GetRow() c = event.GetCol() text = self.GetCellValue(r, c) # self.text - text before change # text - text after change undo = UndoText(self, self.text, text, r, c) stockUndo.append(undo) if stockRedo: # this might be surprising, but it is a standard behaviour # in all spreadsheets del stockRedo[:] toolbar.EnableTool(ID_REDO, False) def OnColSize(self, event): toolbar = self.GetParent().toolbar if (toolbar.GetToolEnabled(ID_UNDO) == False): toolbar.EnableTool(ID_UNDO, True) pos = event.GetRowOrCol() size = self.GetColSize(pos) undo = UndoColSize(self, pos, size) stockUndo.append(undo) if stockRedo: del stockRedo[:] toolbar.EnableTool(ID_REDO, False) def OnRowSize(self, event): toolbar = self.GetParent().toolbar if (toolbar.GetToolEnabled(ID_UNDO) == False): toolbar.EnableTool(ID_UNDO, True) pos = event.GetRowOrCol() size = self.GetRowSize(pos) undo = UndoRowSize(self, pos, size) stockUndo.append(undo) if stockRedo: del stockRedo[:] toolbar.EnableTool(ID_REDO, False) class Newt(wx.Frame): def __init__(self,parent,id,title): wx.Frame.__init__(self, parent, -1, title, size=(550, 500)) box = wx.BoxSizer(wx.VERTICAL) menuBar = wx.MenuBar() menu = wx.Menu() quit = wx.MenuItem(menu, ID_QUIT, '&Quit\tCtrl+Q', 'Quits Newt') quit.SetBitmap(wx.Bitmap('icons/exit16.png')) menu.AppendItem(quit) menuBar.Append(menu, '&File') self.Bind(wx.EVT_MENU, self.OnQuitNewt, id=ID_QUIT) self.SetMenuBar(menuBar) self.toolbar = wx.ToolBar(self, id=-1, style=wx.TB_HORIZONTAL | wx.NO_BORDER | wx.TB_FLAT | wx.TB_TEXT) self.toolbar.AddSimpleTool(ID_UNDO, wx.Bitmap('icons/undo.png'), 'Undo', '') self.toolbar.AddSimpleTool(ID_REDO, wx.Bitmap('icons/redo.png'), 'Redo', '') self.toolbar.EnableTool(ID_UNDO, False) self.toolbar.EnableTool(ID_REDO, False) self.toolbar.AddSeparator() self.toolbar.AddSimpleTool(ID_EXIT, wx.Bitmap('icons/exit.png'), 'Quit', '') self.toolbar.Realize() self.toolbar.Bind(wx.EVT_TOOL, self.OnUndo, id=ID_UNDO) self.toolbar.Bind(wx.EVT_TOOL, self.OnRedo, id=ID_REDO) self.toolbar.Bind(wx.EVT_TOOL, self.OnQuitNewt, id=ID_EXIT) box.Add(self.toolbar, border=5) box.Add((5,10), 0) self.SetSizer(box) self.sheet1 = MySheet(self) self.sheet1.SetNumberRows(55) self.sheet1.SetNumberCols(25) for i in range(self.sheet1.GetNumberRows()): self.sheet1.SetRowSize(i, ID_ROWSIZE) self.sheet1.SetFocus() box.Add(self.sheet1, 1, wx.EXPAND) self.CreateStatusBar() self.Centre() self.Show(True) def OnUndo(self, event): if len(stockUndo) == 0: return a = stockUndo.pop() if len(stockUndo) == 0: self.toolbar.EnableTool(ID_UNDO, False) a.undo() stockRedo.append(a) self.toolbar.EnableTool(ID_REDO, True) def OnRedo(self, event): if len(stockRedo) == 0: return a = stockRedo.pop() if len(stockRedo) == 0: self.toolbar.EnableTool(ID_REDO, False) a.redo() stockUndo.append(a) self.toolbar.EnableTool(ID_UNDO, True) def OnQuitNewt(self, event): self.Close(True) app = wx.App() Newt(None, -1, 'Newt') app.MainLoop()
stockUndo = [] stockRedo = []
There are two list objects. stockUndo
is a list that holds all changes that we can undo. The stockRedo
keeps all changes that can be redone. The changes are instantiated into a UndoText
object. This object has two methods: undo and redo.
class MySheet(CSheet): def __init__(self, parent): CSheet.__init__(self, parent)
Our example inherits from CSheet class. It is a grid widget with some additional logic.
self.SetRowLabelAlignment(wx.ALIGN_CENTRE, wx.ALIGN_CENTRE)
Here we center the labels in rows. By default, they are aligned to the right.
r = event.GetRow() c = event.GetCol() text = self.GetCellValue(r, c) # self.text - text before change # text - text after change undo = UndoText(self, self.text, text, r, c) stockUndo.append(undo)
Every time we do some changes, an UndoText object is created and appended to the stockUndo list..
if stockRedo: # this might be surprising, but it is a standard behaviour # in all spreadsheets del stockRedo[:] toolbar.EnableTool(ID_REDO, False)
Basically, if we undo some changes and then start typing again, all redo changes are lost. OpenOffice Calc works this way, Gnumeric as well.
if len(stockUndo) == 0: self.toolbar.EnableTool(ID_UNDO, False) ... self.toolbar.EnableTool(ID_REDO, True)
The undo and redo buttons are enabled or disabled accordingly. If there is nothing to undo, the undo button is disabled.
a = stockUndo.pop() if len(stockUndo) == 0: self.toolbar.EnableTool(ID_UNDO, False) a.undo() stockRedo.append(a)
If we click undo, we pop up an UndoText
object from the stockUndo list. Call the undo()
method and append the object to the stockRedo list.
Configuring application settings
Many applications allow users to configure their settings. Users can toggle tooltips on and of, change fonts, default download paths etc. Mostly they have a menu option called preferences. Application settings are saved to the hard disk, so that users do not have to change the settings each time the application starts.
In wxPython we have wx.Config
class to do our job.
On Linux, settings are stored in a simple hidden file. This file is located in the home user directory by default. The location of the configuration file can be changed. The name of the file is specified in the constructor of the wx.Config
class. In the following code example, we can cofigure the size of the window. If there is no configuration file, the height and the width of the window is set to the defaul 250px value. We can set these values to a range from 200 - 500px. After we save our values and restart the application, the window size is set to our preffered values.
#!/usr/bin/python # myconfig.py import wx class MyConfig(wx.Frame): def __init__(self, parent, id, title): self.cfg = wx.Config('myconfig') if self.cfg.Exists('width'): w, h = self.cfg.ReadInt('width'), self.cfg.ReadInt('height') else: (w, h) = (250, 250) wx.Frame.__init__(self, parent, id, title, size=(w, h)) wx.StaticText(self, -1, 'Width:', (20, 20)) wx.StaticText(self, -1, 'Height:', (20, 70)) self.sc1 = wx.SpinCtrl(self, -1, str(w), (80, 15), (60, -1), min=200, max=500) self.sc2 = wx.SpinCtrl(self, -1, str(h), (80, 65), (60, -1), min=200, max=500) wx.Button(self, 1, 'Save', (20, 120)) self.Bind(wx.EVT_BUTTON, self.OnSave, id=1) self.statusbar = self.CreateStatusBar() self.Centre() self.Show(True) def OnSave(self, event): self.cfg.WriteInt("width", self.sc1.GetValue()) self.cfg.WriteInt("height", self.sc2.GetValue()) self.statusbar.SetStatusText('Configuration saved, %s ' % wx.Now()) app = wx.App() MyConfig(None, -1, 'myconfig.py') app.MainLoop()
Here we have the contents of a configuration file to our code example. It consists of two key, value pairs.
$ cat .myconfig height=230 width=350

Mouse gestures
A mouse gesture is a way of combining computer mouse movements and clicks which the software recognizes as a specific command. We can find mouse gestures in such applications like Firefox or Opera. They help users save their time while browsing on the Interent. Mouse gestures are created with wx.lib.gestures.MouseGestures
class in wxPython.
Available gestures:
- L for left
- R for right
- U for up
- D for down
- 7 for northwest
- 9 for northeast
- 1 for southwest
- 3 for southeast
If you wonder why these numbers were chosen, have a look at the numerical pad. Mouse gestures can be combined. This way 'RDLU' is a mouse gesture triggered, when we do a square with a mouse pointer.
Possible flags are:
- wx.MOUSE_BTN_LEFT
- wx.MOUSE_BTN_MIDDLE
- wx.MOUSE_BTN_RIGHT
#!/usr/bin/python # mousegestures.py import wx import wx.lib.gestures as gest class MyMouseGestures(wx.Frame): def __init__ (self, parent, id, title): wx.Frame.__init__(self, parent, id, title, size=(300, 200)) panel = wx.Panel(self, -1) mg = gest.MouseGestures(panel, True, wx.MOUSE_BTN_LEFT) mg.SetGesturePen(wx.Colour(255, 0, 0), 2) mg.SetGesturesVisible(True) mg.AddGesture('DR', self.OnDownRight) self.Centre() self.Show(True) def OnDownRight(self): self.Close() app = wx.App() MyMouseGestures(None, -1, 'mousegestures.py') app.MainLoop()
In our example, we have registered a mouse gesture for a panel. Mouse gesture is triggered, when a left button is pressed and we go down and right with a cursor. As in letter 'L'. Our mouse gesture will close the application.
mg = gest.MouseGestures(panel, True, wx.MOUSE_BTN_LEFT)
If we want to use mouse gestures, we have to create a MouseGesture
object. The first parameter is a window, where the mouse gesture is registered. Second parameter defines a way to register a gesture. True is for automatic, False for manual. Manual is not fully implemented and we are happy with the automatic way. Last parameter defines a mouse button, which will be pressed when triggering gestures. The button can be later changed with the SetMouseButton()
method.
mg.SetGesturePen(wx.Colour(255, 0, 0), 2)
Our gestures will be painted as red lines. They will be 2 pixels wide.
mg.SetGesturesVisible(True)
We set this gesture visible with the SetGesturesVisible()
method.
mg.AddGesture('DR', self.OnDownRight)
We register a mouse gesture with the AddGesture()
method. The first parameter is the gesture. Second parameter is the method triggered by the gesture.
In this chapter, we presented some tips in wxPython.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论