Розміщення елементів інтерфейсу
                                    Умови завершення
                                    
                        
                        Метод pack

Властивість fill

Властивість padx

Властивість pady

Властивість ipadx

Властивість ipady

Властивість side
 
 
Метод grid

Клітинки таблиці grid можна об'єднувати методом rowspan та columnspan, а властивість sticky дозволяє вирівнювати вміст клітинки за сторонами: N+E+W+S
from tkinter import *
import tkinter
def show_paris():
    global new
    napys2.delete(1.0,END)
    napys2.insert(INSERT,"Текст про Париж"+"\n")
    if CheckVar1.get():
        new = PhotoImage(file = "paris.gif")
    else:
        new = PhotoImage(file = "paris1.gif")
    label.configure(image = new)
def show_berlin():
    global new
    napys2.delete(1.0,END)
    napys2.insert(INSERT,"Текст про Berlin"+"\n")
    if CheckVar1.get():
        new = PhotoImage(file = "berlin.gif")
    else:
        new = PhotoImage(file = "berlin1.gif")
    label.configure(image = new)
    
def show_london():
    global new
    napys2.delete(1.0,END)
    napys2.insert(INSERT,"Текст про Лондон"+"\n")
    if CheckVar1.get():
        new = PhotoImage(file = "london.gif")
    else:
        new = PhotoImage(file = "london1.gif")
    label.configure(image = new)
           
root = Tk()
root.title("Найпростіше вікно")
root.geometry("600x200")
frame = Frame(root)
frame.grid(row=0, column=0, sticky=N+E+W+S)
knopka=Button(frame, text="Paris", command=show_paris)
knopka.grid(row=0, column=0, pady=5,sticky=S)
knopka2=Button(frame, text="Berlin", command=show_berlin)
knopka2.grid(row=1, column=0, pady=5,sticky=S)
knopka3=Button(frame, text="London", command=show_london)
knopka3.grid(row=2, column=0, pady=5,sticky=S)
CheckVar1 = IntVar()
praporets = Checkbutton (frame, text = "night", variable = CheckVar1, onvalue = 1, offvalue = 0, height=5, width = 20)
praporets.grid(row=3, column=0,sticky=S)
napys2 = Text (root, height=10, width=30)
napys2.insert(INSERT,"Тут буде результат програми")
napys2.grid(row=0, column=1)
new=PhotoImage()
label = Label(root,image=new, height=150, width=150)
label.grid(row=0, column=2, padx=15, sticky=N+E+W+S)
root.mainloop()

Вікно містить три стовпці елементів: рамка frame, котра у свою чергу містить кнопки та прапорець, текстове поле та зображення.
Остання зміна: Вівторок 28 квітня 2015 15:23 PM
