Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Learing material for Python programming language, Thesis of Computer Programming

This learning module is for advance programming for second year college students.

Typology: Thesis

2020/2021

Uploaded on 04/21/2022

franz-natayada
franz-natayada 🇵🇭

4 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Python Tkinter – Cheat Sheet
Basic Level
Widget (Grouping)
Tk.Frame, ttk.Frame
Ttk.LabelFrame
Tk.PanedWindow
Ttk.Notebook
Common Properties:
Purpose
Displays set of widgets as one unit
Frame but with border and title
Group widgets in re-sizable panes
Tabbed set of frames, only one visible at a time
background, foreground, width, height, borderwidth, text,
font, cursor, activeforeground, activebackground, image.
Specific Properties:
1- Scale: from_ , to. orient, resolution.
2- Radiobutton: variable, value.
3- Spinbox: from_ , to, textvariable.
4-Button: command.
5- Checkbutton: onvalue, offvalue, variable.
6- Combobox: textvariable, values.
7- Progressbar: orient, mode, step.
8- Text: wrap, xscrollcommand, yscrollcommand.
9- Scrollbar: orient, command.
Create Widgets
>>> widget_name= ttk.Label ( root, text = ‘Example Text’ )
Set Widget Properties
>>> widget_name.config ( text = ‘Example Text’ )
The most commonly used GUI programming toolkit for
Python.
How to import?
>>> import tkinter or from tkinter import *
Create Treeview
>>> treeview = ttk.Treeview ( root )
>>> treeview.pack ( )
>>> treeview.insert ( ‘ ‘, ‘item1’, text = ‘First item’)
>>> treeview.insert ( ‘ ‘, ‘item2’, text = ‘Second item’)
>>> treeview.cofig (height = 5, column = (‘Version’))
>>> treeview.column (‘Version’, width = 50, anchor = CENTER)
Create Cascading Menu
>>> root.option_add (‘*tearoff’, False)
>>> menubar = Menu (root)
>>> root.config (menu = menubar)
>>> file = Menu (menubar)
>>> edit= Menu (menubar)
>>> help_ = Menu (menubar)
>>> menubar.add_cascade (menu = file, label = ‘File’)
>>> menubar.add_cascade (menu = edit, label = ‘Edit’)
>>> menubar.add_cascade (menu = help_, label = ‘Help’)
>>> file.add_command (label = ‘New’, command = lambda: print(‘New
File’)
>>> file.add_separator ()
>>> file.entryconfig ( ‘New’, accelerator = ‘Ctrl + N’)
File Dialog
>>> from tkinter import filedialog
>>> filename = filedialog.askopenfile ( )
Color Chooser
>>> from tkinter import colorchooser
>>> colorchooser.askcolor ( initialcolor = ‘#FFFFFF’ )
Popup Message
>>> from tkinter import messagebox
>>> messagebox.showinfo( title = ‘Example’, message = ‘some text’ )
Widget (information)
Purpose
Tk.Label, ttk.Label
Display static text or image
Tk.Message
Display static multi line text
Ttk.Separator
Display a horizontal or vertical separator bar
Ttk.Progressbar
Show status of running operation
Ttk.Treeview
Display hierarchical collection of items
Application Main Window
How to instantiate main window of application?
>>> root = Tk ( )
Widgets
Import ‘generic’ widgets: >>> import tkinter
Import ‘styled’ widgets: >>> from tkinter import ttk
Widget (Interactive)
Purpose
Execute a command, function or task
Implements Top-level, pull-down and popup menus
Display popup or pull-down menu when activated
Creates a popup menu, and a button to display
Text entry (one line only)
Text entry (multiple lines)
On-Off, True-False selection
One or Multiple selections
Selection from a list of alternatives
Combined text field with a pop-down list
Moving slider for selecting numerical values
Note: Widgets with tk are generic whereas ttk are styled.

Partial preview of the text

Download Learing material for Python programming language and more Thesis Computer Programming in PDF only on Docsity!

Python Tkinter – Cheat Sheet

Basic Level

Widget (Grouping) Tk.Frame, ttk.Frame Ttk.LabelFrame Tk.PanedWindow Ttk.Notebook

Common Properties:

Purpose Displays set of widgets as one unit Frame but with border and title Group widgets in re-sizable panes Tabbed set of frames, only one visible at a time

background, foreground, width, height, borderwidth, text,

font, cursor, activeforeground, activebackground, image.

Specific Properties:

1- Scale: from_ , to. orient, resolution.

2- Radiobutton: variable, value.

3- Spinbox: from_ , to, textvariable.

4-Button: command.

5- Checkbutton: onvalue, offvalue, variable.

6- Combobox: textvariable, values.

7- Progressbar: orient, mode, step.

8- Text: wrap, xscrollcommand, yscrollcommand.

9- Scrollbar: orient, command.

Create Widgets

>>> widget_name= ttk.Label ( root, text = ‘Example Text’ )

Set Widget Properties

>>> widget_name.config ( text = ‘Example Text’ )

The most commonly used GUI programming toolkit for

Python.

How to import?

>>> import tkinter or from tkinter import *

Create Treeview

treeview = ttk.Treeview ( root ) treeview.pack ( ) treeview.insert ( ‘ ‘, ‘item1’, text = ‘First item’) treeview.insert ( ‘ ‘, ‘item2’, text = ‘Second item’) treeview.cofig (height = 5, column = (‘Version’)) treeview.column (‘Version’, width = 50, anchor = CENTER)

Create Cascading Menu

root.option_add (‘*tearoff’, False) menubar = Menu (root) root.config (menu = menubar) file = Menu (menubar) edit= Menu (menubar) help_ = Menu (menubar) menubar.add_cascade (menu = file, label = ‘File’) menubar.add_cascade (menu = edit, label = ‘Edit’) menubar.add_cascade (menu = help_, label = ‘Help’) file.add_command (label = ‘New’, command = lambda: print(‘New File’) file.add_separator () file.entryconfig ( ‘New’, accelerator = ‘Ctrl + N’)

File Dialog

from tkinter import filedialog filename = filedialog.askopenfile ( )

Color Chooser

from tkinter import colorchooser colorchooser.askcolor ( initialcolor = ‘#FFFFFF’ )

Popup Message

from tkinter import messagebox messagebox.showinfo( title = ‘Example’, message = ‘some text’ ) Widget (information) Purpose Tk.Label, ttk.Label Display static text or image Tk.Message Display static multi line text Ttk.Separator Display a horizontal or vertical separator bar Ttk.Progressbar Show status of running operation Ttk.Treeview Display hierarchical collection of items

Application Main Window

How to instantiate main window of application?

>>> root = Tk ( )

Widgets

Import ‘generic’ widgets: >>> import tkinter

Import ‘styled’ widgets: >>> from tkinter import ttk

Widget (Interactive) Purpose Ttk.Button, tk.Button Execute a command, function or task Tk.Menu Implements Top-level, pull-down and popup menus Ttk.Menubutton Display popup or pull-down menu when activated Tk.OptionMenu Creates a popup menu, and a button to display Tk.Entry, ttk.Entry Text entry (one line only) Tk.Text Text entry (multiple lines) Tk.Checkbutton, ttk.Checkbutton On-Off, True-False selection Tk.Radiobutton, ttk.Radiobutton One or Multiple selections Tk.Listbox Selection from a list of alternatives Ttk.Combobox Combined text field with a pop-down list Tk.Scale, ttk.Scale Moving slider for selecting numerical values Note: Widgets with tk are generic whereas ttk are styled.