#Set theme and style
self.theme = ttk.Style()
self.theme.theme_use('Arc')
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from tkinter import *
class Application(Tk):
def __init__(self):
Tk.__init__(self)
self.title('Textarea')
#self.geometry('300x400+200+200') # ширина=500, высота=400, x=300, y=200
self.protocol('WM_DELETE_WINDOW', self.quit) # обработчик закрытия окна
self.resizable(True, True) # размер окна может быть изменен
self.inline = StringVar()
self.text = Text(wrap=NONE)
self.vscrollbar = Scrollbar(orient='vert', command=self.text.yview)
self.text['yscrollcommand'] = self.vscrollbar.set
self.hscrollbar = Scrollbar(orient='hor', command=self.text.xview)
self.text['xscrollcommand'] = self.hscrollbar.set
# размещаем виджеты
self.text.grid(row=0, column=0, sticky='nsew')
self.vscrollbar.grid(row=0, column=1, sticky='ns')
self.hscrollbar.grid(row=1, column=0, sticky='ew')
# конфигурируем упаковщик, чтобы текстовый виджет расширялся
self.rowconfigure(0, weight=1)
self.columnconfigure(0, weight=1)
root=Application()
root.mainloop()
sys.exit()
####
rev = {"#%d"%x:False for x in range(1,8)}
def treeview_sort_column(tv, col):
l = [(tv.set(k, col), k) for k in tv.get_children('')]
l.sort(reverse=rev[col])
for k in rev.keys():
tv.heading(k,text=tv.heading(k,"text").replace("v","").replace("^",""))
tv.heading(col,text=["^","v"][rev[col]]+tv.heading(col,"text"))
rev[col]=not rev[col]
for index, (val, k) in enumerate(l):
tv.move(k, '', index)
tree.place()
tree.heading("#1", text=" Код", command=lambda:treeview_sort_column(tree,"#1"))
tree.column("#1", minwidth=0, width=35)
tree.heading("#2", text=" Фамилия", command=lambda:treeview_sort_column(tree,"#2"))
tree.heading("#3", text=" Имя", command=lambda:treeview_sort_column(tree,"#3"))
tree.heading("#4", text=" Отчество", command=lambda:treeview_sort_column(tree,"#4"))
tree.heading("#5", text=" Год", command=lambda:treeview_sort_column(tree,"#5"))
tree.column("#5", minwidth=0, width=90)
tree.heading("#6", text=" Школа", command=lambda:treeview_sort_column(tree,"#6"))
tree.column("#6", minwidth=0, width=50)
tree.heading("#7", text=" Класс", command=lambda:treeview_sort_column(tree,"#7"))
####
>>> from tkinter import *
>>> from tkinter.ttk import *
>>> tk = Tk()
>>> v1 = StringVar(tk)
>>> e1 = Entry(tk,textvariable=v1)
>>> e1.pack()
>>> v2 = StringVar(tk)
>>> e2 = Entry(tk,textvariable=v2)
>>> e2.pack()
>>> v3 = StringVar(tk)
>>> e3 = Entry(tk,textvariable=v3)
>>> e3.pack()
>>> v4 = StringVar(tk)
>>> e4 = Entry(tk,textvariable=v4)
>>> e4.pack()
>>> print(v1.get(),v2.get(),v3.get(),v4.get())
from tkinter import *
from tkinter.ttk import *
from datetime import *
root = Tk()
timeVar = StringVar()#Это переменная для надписи
Label(root,textvar=timeVar, font=('Verdana', 16, 'bold')).pack()
def update():
timeVar.set(datetime.now().strftime("%H:%M:%S"))
root.after(1000, update)#тут добавляем вызов через 1000мс из mainloop
update()#вызываем первый раз
root.mainloop()#это аналог while True
icon="данные в base64"
self.root.tk.call('wm', 'iconphoto', root._w, PhotoImage(data=icon))
from tkinter import *
import tkinter.ttk as ttk
root = Tk()
tree = ttk.Treeview(root)
def select(e):
print ([tree.item(x) for x in tree.selection()])
tree["columns"]=("one","two")
tree.column("one", width=100 )
tree.column("two", width=100)
tree.heading("one", text="coulmn A")
tree.heading("two", text="column B")
tree.insert("" , 0, text="Line 1", values=("1A","1b"))
id2 = tree.insert("", 1, "dir2", text="Dir 2")
tree.insert(id2, "end", "dir 2", text="sub dir 2", values=("2A","2B"))
##alternatively:
tree.insert("", 3, "dir3", text="Dir 3")
tree.insert("dir3", 3, text=" sub dir 3",values=("3A"," 3B"))
tree.bind("<<TreeviewSelect>>", select, "+")
tree.pack()
root.mainloop()
from tkinter import *
c = Canvas(width=160, height=100, bg='grey80')
c.pack()
oval = c.create_oval(30, 10, 130, 80, fill="orange")
def oval_func(event):
print("Зачем ты нажал на этот овал?")
def oval_func1(event):
print("Навел мышью да?")
c.tag_bind(oval, '<Button-1>', oval_func)
c.tag_bind(oval, '<Motion>', oval_func1)