tkinter

In [ ]:
from tkinter import *
import tkinter
root = Tk()
In [ ]:
def but_command():
    print("Hey!")

def clicked_command(event):
    print("I'm clicked")
    
    
but = Button(root, text="Нажми на меня")
but.bind("<Button-1>", clicked_command)
but.bind("<Button-2>", but_command)
but.pack()
In [ ]:
import random
lb = Label()
def but_command(event):
    lb['text'] = str(random.rand())

but.bind("<Control-Button-1>", but_command)
In [ ]:
class MyButton():
    def __init__(self, text, rt=root):
        self.but = Button(rt, text="Напечатать")
        self.label = Label(rt)
        self.text = text
        self.but.bind("<Button-1>", self.printer)
        self.but.pack()
        self.label.pack()
    def printer(self, event):
        self.label['text'] = self.text + str(random.randint(0, 9))

        
In [ ]:
ent = Entry()
ent.pack()

but = Button(text="В консоль")
def printer(event):
    print(ent.get())

but.bind("<Shift-Button-1>", printer)    
but.pack()
In [ ]:
field = Text()
field.pack()

but = Button(text="В консоль")
def printer(event):
    print("start", ent.get(), "end", sep="\n")

but.bind("<Shift-Button-1>", printer)
but.pack()
In [ ]:
field = Text()
field.pack()

new = Entry(width=100)
new.pack()

but = Button(text="Добавить")
def add(event):
    field.insert(END, new.get() + '\n')
    new.delete(0, len(new.get()))

but.bind("<Button-1>", add)
but.pack()
In [ ]:
 
In [ ]:
def change():
    print(var.get())

var=IntVar()
var.set(1)
rad0 = Radiobutton(root,text="Первая",
          variable=var,value=0, command=change)
rad1 = Radiobutton(root,text="Вторая",
          variable=var,value=1, command=change)
rad2 = Radiobutton(root,text="Третья",
          variable=var,value=2, command=change) 
rad0.pack()
rad1.pack()
rad2.pack()
In [ ]:
def change1():
    print(c1.get())

def change2():
    print(c2.get())    
    
c1 = IntVar()
c2 = IntVar()
che1 = Checkbutton(root,text="Первый флажок",
          variable=c1,onvalue=1,offvalue=0, command=change1)
che2 = Checkbutton(root,text="Второй флажок",
          variable=c2,onvalue=2,offvalue=0, command=change2)
che1.pack()
che2.pack()
In [ ]:
def confirm():
    print(lis.curselection())

    
r = ['Linux','Python','Tk','Tkinter']
lis = Listbox(root,selectmode=MULTIPLE,height=4)
for i in r:
     lis.insert(END,i)
     
lis.pack()

but = Button(text=['Confirm'], command=confirm)
but.pack()
In [ ]:
def f(a):
    print(a)

def f2(b):
    print(b)
    
sca1 = Scale(root,orient=HORIZONTAL,length=300,
          from_=0,to=100,tickinterval=10,resolution=5, command=f)
sca2 = Scale(root,orient=VERTICAL,length=400,
          from_=1,to=2,tickinterval=0.1,resolution=0.1, command=f2) 

sca1.pack()
sca2.pack()
In [ ]:
tx = Text(root,width=40,height=3,font='14')
scr = Scrollbar(root,command=tx.yview)
tx.configure(yscrollcommand=scr.set)
 
tx.grid(row=0,column=0)
scr.grid(row=0,column=1)
In [ ]:
v = StringVar()
ent1 = Entry (root, textvariable = v,bg="black",fg="white")
ent2 = Entry(root, textvariable = v)
ent1.pack()
ent2.pack()
In [ ]:
 
In [ ]:
canvas = Canvas(root)
canvas.create_line(15, 25, 200, 25)
canvas.create_line(300, 35, 300, 200, dash=(4, 2))
canvas.create_line(55, 85, 155, 85, 105, 180, 55, 85, fill='green')

canvas.pack(fill=BOTH, expand=1)
In [ ]:
canvas = Canvas(self)
canvas.create_rectangle(30, 10, 120, 80, 
    outline="black", fill="#fb0")
canvas.create_rectangle(150, 10, 240, 80, 
    outline="#f50", fill="#f50")
canvas.create_rectangle(270, 10, 370, 80, 
    outline="#05f", fill="#05f")

canvas.pack(fill=BOTH, expand=1)
In [ ]:
canvas = Canvas(self)
canvas.create_oval(10, 10, 80, 80, outline="gray", 
    fill="gray", width=2)
canvas.create_oval(110, 10, 210, 80, outline="gray", 
    fill="gray", width=2)
canvas.create_rectangle(230, 10, 290, 60, 
    outline="gray", fill="gray", width=2)
canvas.create_arc(30, 200, 90, 100, start=0, 
    extent=210, outline="gray", fill="gray", width=2)

points = [150, 100, 200, 120, 240, 180, 210, 
    200, 150, 150, 100, 200]
canvas.create_polygon(points, outline='gray', 
    fill='gray', width=2)

canvas.pack(fill=BOTH, expand=1)
In [ ]:
canvas = Canvas(self)
canvas.create_text(20, 30, anchor=W, font="Purisa",
    text="Most relationships seem so transitory")
canvas.create_text(20, 60, anchor=W, font="Purisa",
    text="They're good but not the permanent one")
canvas.create_text(20, 130, anchor=W, font="Purisa",
    text="Who doesn't long for someone to hold")
canvas.create_text(20, 160, anchor=W, font="Purisa",
    text="Who knows how to love without being told")                   
canvas.create_text(20, 190, anchor=W, font="Purisa",
    text="Somebody tell me why I'm on my own")            
canvas.create_text(20, 220, anchor=W, font="Purisa",
    text="If there's a soulmate for everyone")               
canvas.pack(fill=BOTH, expand=1)
In [ ]:
 
In [ ]:
root.mainloop()