banner



how can i create an upload button in wxpython

  • Interview Question
  • All Tutorials
  • Job Search

What is the use of Button widget in wxPython?

Button widget is most commonly used in any GUI interface as it captures the click event generated by the user and to trigger a handler function bound to it.

wxPython class library offers different types of buttons. A simple traditional button called wx.Button class object which carries some text as its caption. A two-state button is also available which is named as wx.ToggleButton. It's pressed or depressed state will be identified by eventhandler function.

Another type of button, wx.BitmapButton displays a bitmap (image) as icon on its face.

Constructor for wx.Button class and wx.ToggleButton class takes below arguments

These are some important methods of wx.Button class

S.N.

Methods & Description

1

SetLabel()

This will set the button's caption programmatically

2

GetLabel()

This will return the button's caption

3

SetDefault()

Button is set to default for the top level window and imitates the click event on pressing Enter key

Two important methods of wx.ToggleButton class are

S.N.

Methods & Description

1

GetValue()

This will return the state of toggle button (on/off)

2

SetValue()

This will set the state of button programmatically

To create a bitmap button, firstly, a bitmap object should to be constructed out of an image file.

Below variation of wx.Bitmap class constructor is most commonly used

Some of the predefined bitmap type constants are

wx.BITMAP_TYPE_BMP

wx.BITMAP_TYPE_ICO

wx.BITMAP_TYPE_CUR

wx.BITMAP_TYPE_TIFF

wx.BITMAP_TYPE_TIF

wx.BITMAP_TYPE_GIF

wx.BITMAP_TYPE_PNG

wx.BITMAP_TYPE_JPEG

wx.BITMAP_TYPE_PCX

wx.BITMAP_TYPE_ICON

wx.BITMAP_TYPE_ANY

This bitmap object is used as one of the parameters for wx.BitmapButton class constructor.

On some OS platforms, bitmap button displays both bitmap and label and SetLabel() methods will assign the caption. On other platforms it will serve as an internal label.

Normal button as well bitmap button will produce a wx.CommandEvent. EVT_BUTTON binder will associate a handler function to it.

Toggle button on the other hand uses wx.TOGGLEBUTTON binder for event handling.

In below example buttons of all three types are placed in a vertical box sizer of a panel.

Simple button object will be created using the statement

Toggle button can be constructed by using below statement

These buttons will be added into vertical sizer using the following statements

Note − Because of wx.EXPAND flag, toggle button will occupy the entire width of the frame.

Using EVT_BUTTON and EVT_TOGGLEBUTTON binders they are associated with the respective handlers.

Three bitmap buttons will be added into a horizontal box sizer and these buttons display an image as icon as their caption.

Click event of these three buttons will be directed to OnClicked() method.

Internal labels of these buttons will be set to NEW, OPEN and SAVE respectively.

OnClicked() event handler function will retrieve the label of source button which caused the click event and that label is printed on the console.

OnToggle() event handler is triggered when the toggle button is clicked. Its state is read by GetValue() method and accordingly button's caption is set.

Complete code listing is as follows

Above code produces the following output

buttons_output.jpg

Label of pressed button = click Me

Toggle button state off

Toggle button state on

Label of pressed button = NEW

Label of pressed button = OPEN

Label of pressed button = SAVE

how can i create an upload button in wxpython

Source: https://www.wisdomjobs.com/e-university/wxpython-tutorial-1744/wxpython-buttons-23973.html

Posted by: gordonlievaight.blogspot.com

0 Response to "how can i create an upload button in wxpython"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel