编程语言
首页 > 编程语言> > 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()

标签:aa,lb,python,tk,tkinter,root,side,pack
来源: https://blog.csdn.net/qq_34359028/article/details/121445470