'''
主题:tk学习
内容:标签、按钮
时间:2021/10/17
'''
import tkinter as tk
window = tk.Tk()
window.title("my window")
window.geometry('150x100')
var = tk.StringVar()
l = tk.Label(window,
textvariable=var,
bg='green',font=('Arial',12),
width=15,height=2
)
l.pack()
on_hit = False
def hit_me():
global on_hit
if on_hit == False:
on_hit = True
var.set('you hit me')
else:
on_hit = False
var.set('')
b = tk.Button(window,
text='hit me',
width=10,height=1,
command=hit_me
)
b.pack()
window.mainloop()
'''
主题:tk学习
内容:输入、文本框
时间:2021/10/17
'''
import tkinter as tk
window = tk.Tk()
window.title('my window')
window.geometry('200x200')
e = tk.Entry(window,show=None)
e.pack()
t = tk.Text(window,height=2)
t.pack()
def insert_point():
var = e.get()
t.insert('insert',var)
def insert_end():
var = e.get()
t.insert('end',var)
b1 = tk.Button(window,
text='insert point',
width=15,height=2,
command=insert_point
)
b1.pack()
b2 = tk.Button(window,
text='insert end',
command=insert_end
)
b2.pack()
window.mainloop()