Skip to content

Commit

Permalink
cleaned up code examples
Browse files Browse the repository at this point in the history
  • Loading branch information
rasql committed Dec 27, 2019
1 parent 348f2c5 commit 6a9f3c1
Show file tree
Hide file tree
Showing 89 changed files with 288 additions and 284 deletions.
23 changes: 15 additions & 8 deletions docs/app/app.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,24 @@ First, we just do the layout for the buttons::
Button('%').grid(row=1, column=2)
Button(':').grid(row=1, column=3)

.. autoclass:: calc1.Demo

.. image:: calc1.png

.. literalinclude:: calc1.py

:download:`calc1.py<calc1.py>`

Then we are going to add callback functions to the keys::

Button('7', 'App.lb["text"] = float(App.lb["text"])*10 + 7').grid(row=2, column=0)
Button('8', 'App.lb["text"] = float(App.lb["text"])*10 + 8').grid(row=2, column=1)
Button('9', 'App.lb["text"] = float(App.lb["text"])*10 + 9').grid(row=2, column=2)
Button('x').grid(row=2, column=3)

.. autoclass:: calc2.Demo

.. image:: calc2.png

.. literalinclude:: calc2.py

:download:`calc2.py<calc2.py>`

It turns out that it is simpler to place the calculator logic into
a separate function, based on a single character::
Expand Down Expand Up @@ -65,13 +68,17 @@ a separate function, based on a single character::

self.lb['text'] = self.val

.. autoclass:: calc3.Demo

.. image:: calc3.png

.. literalinclude:: calc3.py

:download:`calc3.py<calc3.py>`

And finally we put everything together.
New Calculator instances can be created via a button press or via a menu.

.. autoclass:: calc4.Calculator
.. image:: calc4.png

.. literalinclude:: calc4.py

.. image:: calc4.png
:download:`calc4.py<calc4.py>`
2 changes: 1 addition & 1 deletion docs/app/calc1.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Demo(App):
def __init__(self):
super(Demo, self).__init__()
super().__init__()

App.lb = Label('0.0')
App.lb.grid(columnspan=4)
Expand Down
2 changes: 1 addition & 1 deletion docs/app/calc2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Demo(App):
def __init__(self):
super(Demo, self).__init__()
super().__init__()

s = ttk.Style()
s.configure('TButton', font='Arial 18', padding=5)
Expand Down
2 changes: 1 addition & 1 deletion docs/app/calc3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Demo(App):
def __init__(self):
super(Demo, self).__init__()
super().__init__()

s = ttk.Style()
s.configure('TButton', font='Arial 18', padding=5)
Expand Down
2 changes: 1 addition & 1 deletion docs/app/calc4.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def calculate(self, c):

class Demo(App):
def __init__(self):
super(Demo, self).__init__()
super().__init__()
Button('New calculator', Calculator)
Menu('App')
Item('Calculator', Calculator)
Expand Down
2 changes: 1 addition & 1 deletion docs/basic/button1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class Demo(App):
"""Create different buttons."""
def __init__(self, **kwargs):
super(Demo, self).__init__(**kwargs)
super().__init__(**kwargs)
App.root.title('Button Demo')

Button()
Expand Down
2 changes: 1 addition & 1 deletion docs/basic/button2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class Demo(App):
def __init__(self, **kwargs):
super(Demo, self).__init__(**kwargs)
super().__init__(**kwargs)
App.root.title('Calculator')

frame = ttk.Frame(App.root)
Expand Down
2 changes: 1 addition & 1 deletion docs/basic/button3.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class Demo(App):
def __init__(self, **kwargs):
super(Demo, self).__init__(**kwargs)
super().__init__(**kwargs)
Label('Adding Buttons', font='Arial 24')

Button('Add Button', 'Button(cmd="print(self)")')
Expand Down
2 changes: 1 addition & 1 deletion docs/basic/font1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class Demo(App):
def __init__(self, **kwargs):
super(Demo, self).__init__(**kwargs)
super().__init__(**kwargs)
App.root.title('Windows')

Label('Standard fonts', font='Arial 24')
Expand Down
2 changes: 1 addition & 1 deletion docs/basic/frame1.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Demo(App):
def __init__(self, **kwargs):
super(Demo, self).__init__(**kwargs)
super().__init__(**kwargs)
Label('Embedded frames', font='Arial 24')

types = ['flat', 'raised', 'sunken', 'solid', 'ridge', 'groove']
Expand Down
2 changes: 1 addition & 1 deletion docs/basic/frame2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Demo(App):
def __init__(self, **kwargs):
super(Demo, self).__init__(**kwargs)
super().__init__(**kwargs)

Label('Embedded frames', font='Arial 24')

Expand Down
2 changes: 1 addition & 1 deletion docs/basic/label1.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class Demo(App):
def __init__(self, **kwargs):
super(Demo, self).__init__(**kwargs)
super().__init__(**kwargs)
Label('Show images', font='Arial 24')

lb = Label()
Expand Down
2 changes: 1 addition & 1 deletion docs/basic/label2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class Demo(App):
def __init__(self, **kwargs):
super(Demo, self).__init__(**kwargs)
super().__init__(**kwargs)
Label('Show images as labels', font='Arial 24')

dir = os.listdir('icons')
Expand Down
2 changes: 1 addition & 1 deletion docs/basic/label3.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class Demo(App):
def __init__(self, **kwargs):
super(Demo, self).__init__(**kwargs)
super().__init__(**kwargs)
Label('Show images as buttons', font='Arial 24')

dir = os.listdir('icons')
Expand Down
2 changes: 1 addition & 1 deletion docs/basic/label4.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class Demo(App):
def __init__(self, **kwargs):
super(Demo, self).__init__(**kwargs)
super().__init__(**kwargs)
Label('Show images in a treeview', font='Arial 24')

dir = os.listdir('icons')
Expand Down
2 changes: 1 addition & 1 deletion docs/basic/scale1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class Demo(App):
def __init__(self, **kwargs):
super(Demo, self).__init__(**kwargs)
super().__init__(**kwargs)
Label('Scale widget', font='Arial 24')

Scale()
Expand Down
2 changes: 1 addition & 1 deletion docs/basic/style1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class Demo(App):
def __init__(self, **kwargs):
super(Demo, self).__init__(**kwargs)
super().__init__(**kwargs)
Label('Select a theme', font='Arial 24')

s = ttk.Style()
Expand Down
2 changes: 1 addition & 1 deletion docs/basic/style2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class Demo(App):
def __init__(self, **kwargs):
super(Demo, self).__init__(**kwargs)
super().__init__(**kwargs)
Label('Style TButton', font='Arial 24')
Label('configure TButton')

Expand Down
2 changes: 1 addition & 1 deletion docs/basic/style3.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class Demo(App):
def __init__(self):
super(Demo, self).__init__()
super().__init__()
Label('Widget style', font='Arial 24')

Label('widget state')
Expand Down
2 changes: 1 addition & 1 deletion docs/basic/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class Demo(App):
def __init__(self, **kwargs):
super(Demo, self).__init__(**kwargs)
super().__init__(**kwargs)
App.root.title = 'Tk application template'
Label('Demo application', font='Arial 24')

Expand Down
2 changes: 1 addition & 1 deletion docs/canvas/canvas2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Demo(App):
def __init__(self):
super(Demo, self).__init__()
super().__init__()
Label("Canvas", font="Arial 24")

c = Canvas(width=600, height=300, background='lightblue')
Expand Down
2 changes: 1 addition & 1 deletion docs/canvas/canvas8.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Demo(App):
def __init__(self):
super(Demo, self).__init__()
super().__init__()
Label("Drawing lines", font="Arial 24")

Spinbox('width', 'App.c["width"]=self.val.get()', inc=50, to=1000)
Expand Down
2 changes: 1 addition & 1 deletion docs/concept/concept4.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class Demo(App):
def __init__(self):
super(Demo, self).__init__()
super().__init__()

for i in range(3):
Button()
Expand Down
2 changes: 1 addition & 1 deletion docs/concept/demo1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class Demo(App):
def __init__(self, **kwargs):
super(Demo, self).__init__(**kwargs)
super().__init__(**kwargs)
App.root.title = 'Feet to meters'
Label('feet')
Label('is equivalent to')
Expand Down
2 changes: 1 addition & 1 deletion docs/concept/entry1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class Demo(App):
def __init__(self):
super(Demo, self).__init__()
super().__init__()

App.l = Label("Get widget value", font="Arial 18")

Expand Down
2 changes: 1 addition & 1 deletion docs/concept/entry2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Demo(App):
"""Convert between feet and meters"""
def __init__(self):
super(Demo, self).__init__()
super().__init__()

Label('Convert between feet and meters', font="Arial 18")
Label('Enter value and hit ENTER')
Expand Down
2 changes: 1 addition & 1 deletion docs/event/event.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Here is an exemple which prints mouse **Button** and **Motion** events to the st

class Demo(App):
def __init__(self):
super(Demo, self).__init__()
super().__init__()
Label("Button and Motion events", font="Arial 24")
Label('Display the event in the status bar')

Expand Down
2 changes: 1 addition & 1 deletion docs/event/event1.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Demo(App):
"""Write Button and Motion events to statusbar."""
def __init__(self):
super(Demo, self).__init__()
super().__init__()
Label("Button and Motion events", font="Arial 24")
Label('Display the event in the status bar')

Expand Down
28 changes: 14 additions & 14 deletions docs/intro/intro.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Introduction to Tk
==================
Introduction
============

Tk is a **graphical user interface** (GUI) library. It allows to create windows, buttons and all the
other graphical elements.
Expand Down Expand Up @@ -74,8 +74,8 @@ This is the result:
.. literalinclude:: intro2.py


Classic and new themed widgets
------------------------------
Classic and themed widgets
--------------------------

The elements of a graphical user interface are called **widgets**.
In Tk there are two generations of widgets:
Expand Down Expand Up @@ -108,8 +108,8 @@ The new themed widgets have a gray background and the buttons have uniform size.

.. literalinclude:: intro3.py

Defined our own widget class
----------------------------
Let's define our own widget class
---------------------------------

We are now going to define our own Tk widget classes.
They have the following advantages:
Expand All @@ -130,8 +130,8 @@ This is the new ``Button`` class:
:pyobject: Button


Buttons
-------
Button
------

Buttons can be clicked and are used to execute a command associated with them.
The following demo creates 4 buttons.
Expand All @@ -148,8 +148,8 @@ The following demo creates 4 buttons.
.. literalinclude:: intro5.py


Radiobuttons
------------
Radiobutton
-----------

Radiobuttons are active elements which can be clicked and execute actions.
Only one button is active at any one time.
Expand All @@ -161,8 +161,8 @@ Only one button is active at any one time.
.. literalinclude:: intro6.py


Checkbuttons
------------
Checkbutton
-----------

Checkbuttons are active elements which can be clicked and execute actions.
Multiple checkbuttons can be selected simultaneously.
Expand All @@ -174,8 +174,8 @@ Multiple checkbuttons can be selected simultaneously.
.. literalinclude:: intro7.py


Entry fields
------------
Entry field
-----------

Entry **entry** field presents the user with a single line text field
where he can enter a string value.
Expand Down
3 changes: 1 addition & 2 deletions docs/intro/intro2.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ def run(self):
"""Run the main loop."""
self.root.mainloop()

if __name__ == '__main__':
App().run()
App().run()
3 changes: 1 addition & 2 deletions docs/intro/intro3.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ def run(self):
"""Run the main loop."""
self.root.mainloop()

if __name__ == '__main__':
App().run()
App().run()

0 comments on commit 6a9f3c1

Please sign in to comment.