Python教程

python tkinter

本文主要是介绍python tkinter,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

 

import tkinter as tk

root = tk.Tk()
root.title('tkinter')

frm = tk.Frame(root)
frm.pack(side = tk.LEFT)


en = tk.Entry(frm)
en.pack(side = tk.TOP, fill = tk.BOTH)

def encallback(event):
	print(en.get())
	print(type(en.get()))
en.bind('<KeyRelease>', encallback)

var = tk.StringVar()
var.set(['aa','bb','cc','aa','bb','cc','aa','bb','cc','aa','bb','cc','aa','bb','cc'])
lb = tk.Listbox(frm, height = 25, listvariable = var, selectmode = tk.BROWSE)
lb.pack(side = tk.LEFT, fill = tk.BOTH)

def callback(event):
	i = lb.curselection()
	print(lb.get(i[0]))

lb.bind('<Double-Button-1>', callback)

sb = tk.Scrollbar(frm)
sb.pack(side = tk.RIGHT, fill = tk.Y)

lb['yscrollcommand'] = sb.set
sb['command'] = lb.yview

frm1 = tk.Frame(root)
frm1.pack(side = tk.LEFT)

lb1 = tk.Listbox(frm1, height = 25, width = 80, listvariable = var)
lb1.pack(side = tk.BOTTOM)
lab1 = tk.Label(frm1, text = 'aaa')
lab1.pack(side = tk.LEFT, fill = tk.BOTH)

frm2 = tk.Frame(root)
frm2.pack(side = tk.RIGHT)

lb2 = tk.Listbox(frm2, height = 25, listvariable = var)
lb2.pack(side = tk.BOTTOM)
lab2 = tk.Label(frm2, text = 'bbb')
lab2.pack(side = tk.LEFT, fill = tk.BOTH)

root.mainloop()

这篇关于python tkinter的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!