Book Image

Tkinter GUI Application Development HOTSHOT

By : Bhaskar Chaudhary
Book Image

Tkinter GUI Application Development HOTSHOT

By: Bhaskar Chaudhary

Overview of this book

<p>Tkinter is the built-in GUI package that comes with standard python distributions. This means it is easy to get started right away, without any extra installation or configuration. Tkinter’s strength lies in its simplicity of use and its intuitive nature which makes it suited for programmers and non-programmers alike. Once you get started, you will be surprised to see how a few lines of code can produce powerful GUI applications.</p> <p>Tkinter GUI Application Development Hotshot helps you learn the art of GUI programming—building real-world, productive and fun applications like text editor, drum machine, game of chess, media player, drawing application and many more. Each subsequent project builds on the skills acquired in the previous project. Also, learn to write multi-threaded and multi layered applications using Tkinter. Get to know modern best practices involved in writing GUI programs. Tkinter GUI Application Development Hotshot comes with a rich source of sample codes that you can use in your own projects in any discipline of your choice.</p> <p>Starting with a high level overview of Tkinter that covers the most important concepts involved in writing a GUI application, the book then takes you through a series of real world projects of increasing complexity, developing one project per chapter. After you have developed five full projects, the book provides you with some bare-bone skeleton codes for a few functional but incomplete projects, challenging you to put your skills to test by completing them.</p> <p>Finally, you are provided with tips for writing reusable, scalable, and quality GUI code for larger projects. The appendices provide a quick reference sheet for Tkinter.</p>
Table of Contents (16 chapters)
Tkinter GUI Application Development HOTSHOT
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

The Toplevel window methods


These methods enable communication with the window manager. They are available on the root window (Tk), and also on Toplevel instances.

Note that different window managers behave in different ways. For example, some window managers don't support icon windows; some don't support window groups, and so on.

aspect = wm_aspect(self, minNumer=None, minDenom=None, maxNumer=None, maxDenom=None)

Instruct the window manager to set the aspect ratio (width/height) of this widget to be between minNumer/minDenom and maxNumer/maxDenom. Return a tuple of the actual values if no argument is given.

attributes = wm_attributes(self, *args)

This subcommand returns or sets platform-specific attributes. The first form returns a list of the platform specific flags and their values. The second form returns the value for the specific option. The third form sets one or more of the values. The values are as follows:

On Windows, -disabled gets or sets whether the window is in a disabled state. -toolwindow gets or sets the style of the window

totoolwindow (as defined in the MSDN). -topmost gets or sets whether this is a topmost window (displays above all other windows).

On Macintosh, XXXXX

On Unix, there are currently no special attribute values.

client = wm_client(self, name=None)

Store name in WM_CLIENT_MACHINE property of this widget. Return current value.

colormapwindows = wm_colormapwindows(self, *wlist)

Store list of window names (wlist) into WM_COLORMAPWINDOWS property of this widget. This list contains windows whose colormaps differ from their parents. Return current list of widgets if wlist is empty.

command = wm_command(self, value=None)

Store value in WM_COMMAND property. It is the command which shall be used to invoke the application. Return current command if value is None.

deiconify = wm_deiconify(self)

deiconify this widget. If it was never mapped, it will not be mapped. On Windows, it will raise this widget and give it the focus.

focusmodel = wm_focusmodel(self, model=None)

Set focus model to model, "active" means that this widget will claim the focus itself, "passive" means that the window manager shall give the focus. Return current focus model if model is None.

frame = wm_frame(self)

Return identifier for decorative frame of this widget if present.

geometry = wm_geometry(self, newGeometry=None)

Set geometry to newgeometry of the form =widthxheight+x+y. Return current value if None is given.

grid = wm_grid(self, baseWidth=None, baseHeight=None, widthInc=None, heightInc=None)

Instruct the window manager that this widget shall only be resized on grid boundaries. widthInc and heightInc are the width and height of a grid unit in pixels. baseWidth and baseHeight are the number of grid units requested in Tk_GeometryRequest.

group = wm_group(self, pathName=None)

Set the group leader widgets for related widgets to pathName. Return the group leader of this widget if None is given.

iconbitmap = wm_iconbitmap(self, bitmap=None, default=None)

Set bitmap for the iconified widget to BITMAP. Return the bitmap if None is given. Under Windows, the DEFAULT parameter can be used to set the icon for the widget and any descendants that don't have an icon set explicitly. DEFAULT can be the relative path to a .ico file (example: root.iconbitmap(default='myicon.ico')). See Tkdocumentation for more information.

iconify = wm_iconify(self)

Display widget as icon.

iconmask = wm_iconmask(self, bitmap=None)

Set mask for the icon bitmap of this widget. Return the mask if None is given.

iconname = wm_iconname(self, newName=None)

Set the name of the icon for this widget. Return the name if None is given.

iconposition = wm_iconposition(self, x=None, y=None)

Set the position of the icon of this widget to X and Y. Return a tuple of the current values of X and Y if None is given.

iconwindow = wm_iconwindow(self, pathName=None)

Set widget pathName to be displayed instead of icon. Return the current value if None is given.

maxsize = wm_maxsize(self, width=None, height=None)

Set max width and height for this widget. If the window is gridded, the values are given in grid units. Return the current values if None is given.

minsize = wm_minsize(self, width=None, height=None)

Set min width and height for this widget. If the window is gridded, the values are given in grid units. Return the current values if None is given.

overrideredirect = wm_overrideredirect(self, boolean=None)

Instruct the window manager to ignore this widget if Boolean is given with 1. Return the current value if None is given.

positionfrom = wm_positionfrom(self, who=None)

Instruct the window manager that the position of this widget shall be defined by the user if who is "user", and by its own policy if who is "program".

protocol = wm_protocol(self, name=None, func=None)

Bind function func to command name for this widget. Return the function bound to name if None is given. name could be for example, WM_SAVE_YOURSELF or WM_DELETE_WINDOW.

resizable = wm_resizable(self, width=None, height=None)

Instruct the window manager whether this width can be resized in width or height. Both values are Boolean values.

sizefrom = wm_sizefrom(self, who=None)

Instruct the window manager that the size of this widget shall be defined by the user if who is "user", and by its own policy if who is "program".

state = wm_state(self, newstate=None)

Query or set the state of this widget as one of normal, icon, iconic (see wm_iconwindow), withdrawn, or zoomed (Windows only).

title = wm_title(self, string=None)

Set the title of this widget.

transient = wm_transient(self, master=None)

Instruct the window manager that this widget is transient with regard to widget master.

withdraw = wm_withdraw(self)

Withdraw this widget from the screen such that it is unmapped and forgotten by the window manager. Re-draw it with wm_deiconify.

wm_aspect(self, minNumer=None, minDenom=None, maxNumer=None, maxDenom=None)

Instruct the window manager to set the aspect ratio (width/height) of this widget to be between minNumer/minDenom and maxNumer/maxDenom. Return a tuple of the actual values if no argument is given.

wm_attributes(self, *args)

This subcommand returns or sets platform-specific attributes. The first form returns a list of the platform specific flags and their values. The second form returns the value for the specific option. The third form sets one or more of the values. The values are as follows:

On Windows, -disabled gets or sets whether the window is in a disabled state. -toolwindow gets or sets the style of the window

totoolwindow (as defined in the MSDN). -topmost gets or sets whether this is a topmost window (displays above all other windows).

On Macintosh, XXXXX

On Unix, there are currently no special attribute values.

wm_client(self, name=None)

Store name in WM_CLIENT_MACHINE property of this widget. Return current value.

wm_colormapwindows(self, *wlist)

Store list of window names (wlist) into WM_COLORMAPWINDOWS property of this widget. This list contains windows whose colormaps differ from their parents. Return current list of widgets if wlist is empty.

wm_command(self, value=None)

Store value in WM_COMMAND property. It is the command which shall be used to invoke the application. Return current command if value is None.

wm_deiconify(self)

Deiconify this widget. If it was never mapped, it will not be mapped. On Windows, it will raise this widget and give it the focus.

wm_focusmodel(self, model=None)

Set focus model to model. "active" means that this widget will claim the focus itself, "passive" means that the window manager shall give the focus. Return current focus model if model is None.

wm_frame(self)

Return identifier for decorative frame of this widget if present.

wm_geometry(self, newGeometry=None)

Set geometry to newgeometry of the form =widthxheight+x+y. Return current value if None is given.

wm_grid(self, baseWidth=None, baseHeight=None, widthInc=None, heightInc=None)

Instruct the window manager that this widget shall only be resized on grid boundaries. widthInc and heightInc are the width and height of a grid unit in pixels. baseWidth and baseHeight are the number of grid units requested in Tk_GeometryRequest.

wm_group(self, pathName=None)

Set the group leader widgets for related widgets to pathname. Return the group leader of this widget if None is given.

wm_iconbitmap(self, bitmap=None, default=None)

Set bitmap for the iconified widget to bitmap. Return the bitmap if None is given.

Under Windows, the default parameter can be used to set the icon for the widget and any descendants that don't have an icon set explicitly. DEFAULT can be the relative path to a .ico file (example: root.iconbitmap(default='myicon.ico')). See Tkdocumentation for more information.

wm_iconify(self)

Display widget as icon.

wm_iconmask(self, bitmap=None)

Set mask for the icon bitmap of this widget. Return the mask if None is given.

wm_iconname(self, newName=None)

Set the name of the icon for this widget. Return the name if None is given.

wm_iconposition(self, x=None, y=None)

Set the position of the icon of this widget to X and Y. Return a tuple of the current values of X and X if None is given.

wm_iconwindow(self, pathName=None)

Set widget pathname to be displayed instead of icon. Return the current value if None is given.

wm_maxsize(self, width=None, height=None)

Set max width and height for this widget. If the window is gridded, the values are given in grid units. Return the current values if None is given.

wm_minsize(self, width=None, height=None)

Set min width and height for this widget. If the window is gridded the values are given in grid units. Return the current values if None is given.

wm_overrideredirect(self, boolean=None)

Instruct the window manager to ignore this widget if Boolean is given with 1. Return the current value if None is given.

wm_positionfrom(self, who=None)

Instruct the window manager that the position of this widget shall be defined by the user if who is "user", and by its own policy if who is "program".

wm_protocol(self, name=None, func=None)

Bind function func to command name for this widget. Return the function bound to name if None is given. Name could be for example, WM_SAVE_YOURSELF or WM_DELETE_WINDOW.

wm_resizable(self, width=None, height=None)

Instruct the window manager whether this width can be resized in width or height. Both values are Boolean values.

wm_sizefrom(self, who=None)

Instruct the window manager that the size of this widget shall be defined by the user if who is "user", and by its own policy if who is "program".

wm_state(self, newstate=None)

Query or set the state of this widget as one of normal, icon, iconic (see wm_iconwindow), withdrawn, or zoomed (Windows only).

wm_title(self, string=None)

Set the title of this widget.

wm_transient(self, master=None)

Instruct the window manager that this widget is transient with regard to widget master.

wm_withdraw(self)

Withdraw this widget from the screen such that it is unmapped and forgotten by the window manager. Re-draw it with wm_deiconify.