How to create a frame (Phoenix)

Keywords : Frame.


Introduction :

wx.Frame is a container widget.

It means that it can contain other widgets.

It has the following constructor:

wx.Frame(wx.Window parent, id, string title,
         wx.Point pos = wx.DefaultPosition, wx.Size size = wx.DefaultSize,
         style = wx.DEFAULT_FRAME_STYLE, string name = 'frame')

A constructor is a special kind of a function.

It is called when an object is created.

For us it is only important that when we want to create a new widget, we simply call its constructor.

Python enables parameters with default values.

So the only obligatory parameters in wx.Frame are parent, id and title.

If you specify all values of the parameters in order, you don't need to specify the parameter names.

For example you want to create a wx.Frame widget, which has no parent, its identifier is 100,

the title is 'Title', the position is (100,50) and the size is (100,100).

frame = wx.Frame(None, 100, 'Title', wx.Point(100,50), wx.Size(100,100))

Here we have omitted the pos parameter.

So we must provide explicitly the size parameter.

frame = wx.Frame(None, 100, 'Title', size = wx.Size(100,100))

In the following example we will use other useful features.

Icon's name is icon_wxWidgets.ico.

The icon is located in current directory.

First parameter of an icon's constructor is the file name.

Second parameter specifies the file type.

As you have noticed, the structure of our application has changed.

This is a standard in Python programs.

In Python programs __name__ is a special variable.

More complicated programs consist of several files.

There is usually only one file, which launches the application.

For this file, Python sets the __name__ variable to '__main__'.

This happens when you launch an application from the command line or when you click on the file.

So when you click on the icon.py file or you launch it from the command line, the __name__ variable equals '__main__'.

Then function main() is called.

(info by ZetCode / Jan Bodnar).


Demonstrating :

Tested py3.x, wx4.x and Win10.

Are you ready to use some samples ? ;)

Test, modify, correct, complete, improve and share your discoveries ! (!)


Sample one

img_sample_one.png

   1 # sample_one.py
   2 
   3 """
   4 
   5 Author : Jan Bodnar
   6 Website : zetcode.com
   7 
   8 """
   9 
  10 import wx
  11 
  12 # def main
  13 
  14 #---------------------------------------------------------------------------
  15 
  16 def main():
  17     app = wx.App()
  18 
  19     frame = wx.Frame(None, title='wx.Frame', pos=(350, 300))
  20     frame.SetIcon(wx.Icon('./icons/icon_wxWidgets.ico', wx.BITMAP_TYPE_ICO))
  21     frame.Center()
  22     frame.Show()
  23 
  24     app.MainLoop()
  25 
  26 #---------------------------------------------------------------------------
  27 
  28 if __name__ == '__main__':
  29     main()


Download source

source.zip


Additional Information

Link :

- - - - -

https://wiki.wxpython.org/TitleIndex

https://docs.wxpython.org/


Thanks to

Jan Bodnar (sample_one.py coding), the wxPython community...


About this page

Date(d/m/y) Person (bot) Comments :

15/12/20 - Ecco (Created page for wxPython Phoenix).


Comments

- blah, blah, blah....

How to create a frame (Phoenix) (last edited 2020-12-31 16:14:43 by Ecco)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.