前言
Tkinter是Python的标准GUI库,它提供了丰富的组件和布局管理器,能够帮助我们快速地创建图形用户界面应用程序。
Tkinter具有以下优点:
是Python的标准GUI库,无需安装第三方库即可使用。
操作简单,上手快,使用便利。
提供了丰富的组件和布局管理器,能够满足大多数应用程序的需求。
具有良好的跨平台性,能够在Windows、macOS和Linux等操作系统上运行。
开始
首先导入需要用的模块
from tkinter import *
先创建对象初始化,建立一个大小合适的窗口。 其中.resizable为False表示窗口大小禁止更改
root = Tk()
root.geometry('400x350+300+200')
root.resizable(False, False)
root.title('标题')
root.mainloop()
确定自己所需要各种组件,例如(按钮:Button,标签:Label,文字:Enter,多行文字:Text等待)
root = Tk()
root.geometry('400x350+300+200')
root.resizable(False, False)
root.title('标题')
l1 = Label(text='标签1', bd=0, relief=FLAT, font=('楷体', 15))
l1.place(x=10, y=30)
e1 = Entry(root, bd=2, width=14, font=('楷体', 15))
e1.place(x=90, y=30)
button1 = Button(text='按钮1', bg='#f0a732', command='可加函数def', fg='#f2f7fb', width=3, height=1, bd=4)
button1.place(x=250, y=25)
text1 = Text(root, fg='#f0f0f0', bg='#8c8c8c', font=('宋体', '13'), width=25, height=6, bd=1) #
text1.place(x=30, y=120)
root.mainloop()
其中 .place为调整位置,向右为X轴,下位Y轴,按钮button中command可加函数,点击按钮则则触发改函数。
再补充组件,并更改自己所对应的参数名
root = Tk()
root.geometry('400x350+300+200')
root.resizable(False, False)
root.title('酷狗抓')
l1 = Label(text='音乐名:', bd=0, relief=FLAT, font=('楷体', 15)) # 今日消费
l1.place(x=10, y=30)
e1 = Entry(root, bd=2, width=14, font=('楷体', 15))
e1.place(x=90, y=30)
ulist = []
button1 = Button(