1.简单示例:
import tkinter
#创建主窗口
win = tkinter.Tk()
#设置标题
win.title(" wwww ")
#设置大小和位置
win.geometry(“400x400+200+20”)
win.mainloop()
2.Label控件:
(label标签可以显示文本)
#wraplength 指定text文本中多宽进行换行
#justify 设置换行后的对齐方法
#anchor 位置
label = tkinter.Label(win,
text="a b c d",
bg="pig"
fg="red"
font=("黑体",20),
width=10
height=4)
#显示出来
label.pack()
3.Button控件:
button1 = tkinter.Button(win,
text="按钮",
command=func,
width=10,
height=10)
button1.pack()
button2 =tkinter.Button(win,
text="按钮",
command=win.quit)
button2.pack()
4.Entry控件
#绑定变量
e = tkinter.Variable()
#show 密文显示 show="*"
entry = tkinter.Entry(win,textvariable=e)
entry.pack()
#设置值
e.set("hello world")
#取值
print(e.get())
print(entry.get())
5.点击按钮输出 输入框中的内容
def show():
print(entry.get())
entry = tkinter.Entry(win)
entry.pack()
button = tkinter.Button(win,text="按钮",command=show)
button.pack()
6.Text控件
文本控件,用于显示多行文本
在这里插入代码片
8.checkbutton多选框控件
import tkinter
win = tkinter.Tk()
win.title("wwww")
win.geometry("400x400+200+20")
def updata():
message = ""
if hobby1.get()== True:
message += "money\n"
if hobby2.get()== True:
message += "power\n"
if hobby3.get()== True:
message += "people\n"
#清除txt中的所有内容
text.delete(0.0,tkinter.END)
text.insert(tkinter.INSERT,message)
hobby1 = tkinter.BooleanVar()
check1 = tkinter.Checkbutton(win,text="money",variable=hobby1,command=updata)
check1.pack()
hobby2 = tkinter.BooleanVar()
check2 = tkinter.Checkbutton(win,text="power",variable=hobby2,command=updata)
check2.pack()
hobby3 = tkinter.BooleanVar()
check3 = tkinter.Checkbutton(win,text="people",variable=hobby3,command=updata)
check3.pack()
text = tkinter.Text(win,width=50,height=5)
text.pack()
win.mainloop()