1.开始
最简单的窗口
from tkinter import *
root = TK()
root.mainloop()
mainloop()的作用: 会让窗口循环接收下一个事件,作为程序最后一步
root.title('这是这个窗口标题')
2.控件
1、标签
from tkinter import *
root = TK()
wl.lable(root, text='这是一个标签')
wl.pack()
w2 = lable(root, text='123', background=red)
w2.pack()
root.mainloop()
2、输入框
3、事件绑定
方式一:
but = tkinter.button(root, command=函数名)
方式二:
def mylable(event):
return 0
but = Button(root, text='点击按钮')
but.bind("<button-1>", mylable)
mylable是一个函数名
button-1表示鼠标左击,button-2 表示右击
<Control-Button-1> Ctrl+鼠标左击
3、布局
pick布局
grid布局
4、弹出菜单
消息框
from tkinter.messagebox import *
showinfo(title = '欢迎使用消息框',message= ‘好好学习天天上炕’)
Combox修改事件
self.combox_ip_chose = ttk.Combobox(self.tab)
self.combox_ip_chose["value"] = ('代理ip:一号端口[x]', '代理ip:二号端口[y]',)
self.combox_ip_chose.current(0)
self.combox_ip_chose.place(x=480, y=170, width=200, height=30)
self.combox_ip_chose.bind("<<ComboboxSelected>>", self.proxyHost_change)
def proxyHost_change(self, eventObject):
if self.combox_ip_chose.current() == 0:
settings.proxyHost = 0
else:
settings.proxyHost = 1
print('ip端口:', self.combox_ip_chose.current())