SoFunction
Updated on 2024-11-19

wxpython Learning Notes Day 1

1, import wxpython library
import wx
2, the establishment of the form constructor class
class name ():
def __init__(self, parent, id):
. __init__(self, parent, id, 'tool',size=(300, 200))
3,Create panel panel = (self)
Setting the panel background
('White')
is the status bar, displayed at the bottom of the panel
()
# This is a tool menu, displayed on top of the form, the tool menu is generally a menu with icons
()
# for the menu is also displayed on top of the form
()
# Specific menus above the menu bar
()
About the incident

Parameter one, the time type of the binding
Parameter two, triggered function
Parameter three, identify the id on that form that triggers the
About Image Processing
# Get picture object
image = ('', wx.BITMAP_TYPE_JPEG)
# Acquire bitmap streams
temp = ()
About the specific menu bar
Append method to add a menu item
Parameter one, menu item unique id
Parameter two, menu item name
Parameter three, the text displayed in the status bar when this menu is selected
AppendMenu method for adding the next level menu
Parameter one, menu item unique id
Parameter two, menu item name
Parameter three, specific menu item object
About the form's constructor
(parent, id=-1, title="", pos=,
size=, style=wx.DEFAULT_FRAME_STYLE,
name="frame")
We will see similar parameters in the constructors of other window widgets. The description of the parameter is as follows:
parent: the parent window of the frame. For top-level windows, this value is None. frames are destroyed when their parent window is destroyed. Depending on the platform, frames can be restricted to appear only on top of the parent window. In the case of a multi-document interface, child windows are restricted to move and zoom only within the parent window.
id: wxPython ID number about the new window. You can pass one explicitly. Or pass -1, which will cause wxPython to automatically generate a new ID.
title: title of the window.
pos: an object that specifies the position in the screen of the upper left corner of this new window. In GUI programs, usually (0,0) is the upper left corner of the display. This default (-1,-1) will let the system determine the position of the window.
size: an object that specifies the initial size of this window. This default (-1,-1) will let the system decide the initial size of the window.
style: a constant that specifies the type of the window. You can combine them using the or operation.
name: the intrinsic name of the frame. You can use it later to find this window.
Remember that these parameters will be passed to the constructor method of the parent class: . __init__().
The method for creating a subclass is shown below:
class MyFrame():
def __init__(self):
.__init__(self, None, -1, "My Friendly Window",
(100, 100), (100, 100))
Some attributes about the frame
(False) # Make the frame invisible.
(True) # True is the default value, making the frame visible.
() # Equivalent to (False)
Close Form
()
example program
# Set the encoding used by python
#coding=utf-8
#Load the wx library
import wx
# Framework classes
class ToolbarFrame():
def __init__(self, parent, id):# constructor
# Tectonic framework
. __init__(self, parent, id, 'tool',size=(300, 200))
# Fill Panel
panel = (self)
# Set panel background color
('White')
#Build status bar
statusBar = ()
#Build toolbars
toolbar = ()
# Get the toolbar icon object
image = ('', wx.BITMAP_TYPE_JPEG)
# Get icon bitmap streams
temp = ()
#Build toolbars
((),temp, "New", "Long help for 'New'")
# Setting the toolbar position
()
#Build the menu bar
menuBar = ()
# Create menu items
menu1 = ()
#Add subordinate menu items
((), "C&ut", "Copy in status bar")
# Setting up the divider in the menu item
()
sm = ()
(-1, 'test 1');
(-1, 'test 2');
# Add secondary menu items to primary menu
(-1,'subordinate',sm).
# Add menu items to a single menu bar
(menu1, "File (&F)")
menu2 = ()
nid = ()
(nid, "&Copy", "Copy in status bar")
#Event Binding
(wx.EVT_MENU, , id=nid)
((), "C&ut", "")
((), "&Paste", "")
()
((), "&Options...", "Display Options")
(menu2, "&Edit")
#Setup menu bar display
(menuBar)
# of events triggered
def onQuit(self, event):
#PopupBox
dlg = (None, 'Is this the coolest thing ever!','MessageDialog', wx.YES_NO | wx.ICON_QUESTION)
result = ()
()
#Execute
if __name__ == '__main__':
app = ()
frame = ToolbarFrame(parent=None, id=-1)
()
()
Open Source Project Information
/group/blog/309552
Lecture Development
/blog/150228
wxPython in Action Chinese Documentation
/blog/?id=184
Author sanshi sanshi0815