|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +import tkinter as tk |
| 4 | + |
| 5 | +# --- init --- |
| 6 | + |
| 7 | +root = tk.Tk() |
| 8 | +root.title('Pack') |
| 9 | + |
| 10 | +# --- text --- |
| 11 | + |
| 12 | +text = '\n[very, very, very, very, very long text for example]' |
| 13 | + |
| 14 | +# --- info --- |
| 15 | + |
| 16 | +tk.Label(root, text="Bartłomiej 'furas' Burek (blog.furas.pl)", bg='black', fg='white', width=70).pack() |
| 17 | +tk.Label(root, text="import tkinter as tk", bg='black', fg='yellow', width=70).pack() |
| 18 | + |
| 19 | +# --- align button/label/widget in cell --- |
| 20 | + |
| 21 | +tk.Label(root, text="\n--------- align button/label/widget in cell ---------", bg='grey', fg='yellow', width=70).pack() |
| 22 | +tk.Label(root, text="use in pack(...)\n", bg='grey', fg='white', width=70).pack() |
| 23 | + |
| 24 | +# --- |
| 25 | + |
| 26 | +tk.Button(root, text="\n (nothing) \n"+text).pack() |
| 27 | +tk.Button(root, text="\n anchor='w' (or) anchor=tk.W \n"+text).pack(anchor='w') |
| 28 | +tk.Button(root, text="\n anchor='e' (or) anchor=tk.E \n"+text).pack(anchor='e') |
| 29 | +#tk.Label(root, text="\nCAN'T DO: anchor='we' (or) anchor=tk.W+tk.E\n", fg='red').pack() |
| 30 | +tk.Button(root, text="\n fill='x' (or) fill=tk.X \n"+text).pack(fill='x') |
| 31 | + |
| 32 | +# --- align text in button/label --- |
| 33 | + |
| 34 | +tk.Label(root, text="\n--------- align text in button/label ---------", bg='grey', fg='yellow', width=70).pack() |
| 35 | +tk.Label(root, text="use in Label(...)/Button(...)\n", bg='grey', fg='white', width=70).pack() |
| 36 | +tk.Label(root, text="pack( fill='x' (or) fill=tk.X )", bg='gray', width=70).pack() |
| 37 | + |
| 38 | +# --- |
| 39 | + |
| 40 | +tk.Button(root, text="\n (nothing) \n"+text).pack(fill='x') |
| 41 | +tk.Button(root, text="\n anchor='w' (or) anchor=tk.W \n"+text, anchor='w').pack(fill='x') |
| 42 | +tk.Button(root, text="\n anchor='e' (or) anchor=tk.E \n"+text, anchor='e').pack(fill='x') |
| 43 | + |
| 44 | +# --- align lines in text in button/label --- |
| 45 | + |
| 46 | +tk.Label(root, text="\n--------- align lines in text in button/label ---------", bg='grey', fg='yellow', width=70).pack() |
| 47 | +tk.Label(root, text="use in Label(...)/Button(...)\n", bg='grey', fg='white', width=70).pack() |
| 48 | +tk.Label(root, text="pack( fill='x' (or) fill=tk.X )", bg='gray', width=70).pack() |
| 49 | + |
| 50 | +# --- |
| 51 | + |
| 52 | +tk.Button(root, text="\n (nothing) \n"+text).pack(fill='x') |
| 53 | +tk.Button(root, text="\n justify='left' (or) justify=tk.LEFT \n"+text, justify='left').pack(fill='x') |
| 54 | +tk.Button(root, text="\n justify='right' (or) justify=tk.RIGHT \n"+text, justify='right').pack(fill='x') |
| 55 | +tk.Button(root, text="\n justify='center' (or) justify=tk.CENTER \n"+text, justify='center').pack(fill='x') |
| 56 | + |
| 57 | +# --- info --- |
| 58 | + |
| 59 | +tk.Label(root, text="w = west/left , e = east/right , n = north/top , s = south/bottom", bg='black', fg='white', width=70).pack() |
| 60 | + |
| 61 | +# --- "start the engine" --- |
| 62 | + |
| 63 | +root.mainloop() |
0 commit comments