tkinter参数说明

import tkinter as tk


def add_student():
    result.set('增加学生信息')


def delete_student():
    result.set('删除学生信息')


def change_student():
    result.set('修改学生信息')


def show_student():
    result.set('查看学生信息')


if __name__ == '__main__':
    # 以下代码全部为gui界面的初始化

    # 第1步,实例化对象,建立窗口window
    window = tk.Tk()
    # 第2步,给窗口的可视化起名字
    window.title('学生信息管理系统 V2.1')
    # 第3步,设定窗口的大小(长 * 宽)
    window.geometry('500x650')    

    # tk.StringVar()用于接收用户输入
    result = tk.StringVar()
    result.set(" ")

    # ①关于姓名的 label 和 entry
    textName = tk.StringVar()
    textName.set("")
    labelLine1 = tk.Label(window, text="姓     名:", font=('Arial', 15), width=10).place(x=75, y=50, anchor='nw')
    entryLine1 = tk.Entry(window, show=None, font=('宋体', 15), textvariable=textName, width=20)
    entryLine1.place(x=190, y=50, anchor='nw')  # 显示成明文形式

    # ②关于性别的 label 和 entry
    textSex = tk.StringVar()
    textSex.set("")
    labelLine2 = tk.Label(window, text="性     别:", font=('Arial', 15), width=10)
    labelLine2.place(x=75, y=100, anchor='nw')
    entryLine2 = tk.Entry(window, show=None, font=('Arial', 15), textvariable=textSex, width=18)
    entryLine2.place(x=190, y=100, anchor='nw')

    # ③关于电话的 label 和 entry
    textPhone = tk.StringVar()
    textPhone.set("")
    labelLine3 = tk.Label(window, text="电     话:", font=('Arial', 15), width=10).place(x=75, y=150, anchor='nw')
    entryLine3 = tk.Entry(window, show=None, font=('Arial', 15), textvariable=textPhone, width=18)
    entryLine3.place(x=190, y=150, anchor='nw')

    # 关于"添加"组件,此处绑定函数add_student用于添加学生信息
    button1_add = tk.Button(window, text='添   加', bg='silver', font=('Arial', 12), command=add_student, width=8)
    button1_add.place(x=40, y=220, anchor='nw')
    # 关于"删除"组件,此处绑定函数delete_student用于删除学生信息
    button2_delete = tk.Button(window, text='删   除', bg='silver', font=('Arial', 12), command=delete_student, width=8)
    button2_delete.place(x=150, y=220, anchor='nw')
    # 关于"修改"组件,此处绑定函数change_student用于修改学生信息
    button3_change = tk.Button(window, text='修   改', bg='silver', font=('Arial', 12), command=change_student, width=8)
    button3_change.place(x=260, y=220, anchor='nw')
    # 关于"显示"组件,此处绑定函数show_student用于显示学生信息
    button4_show = tk.Button(window, text='显   示', bg='silver', font=('Arial', 12), command=show_student, width=8)
    button4_show.place(x=370, y=220, anchor='nw')
    # 下边两行代码是在gui界面显示我的作者信息
    labelLine_Name = tk.Label(window, text="@Author:", font=('宋体', 13), width=10).place(x=130, y=260, anchor='nw')
    labelLine_myID = tk.Label(window, text="飞飞", font=('宋体', 13), width=10).place(x=250, y=260, anchor='nw')

    show_result = tk.Label(window, bg="white", fg="black", font=("宋体", 12), bd='0', anchor='nw', textvariable=result)
    show_result.place(x="25", y="300", width="450", height="300")
    window.protocol('WM_DELETE_WINDOW', custom_over)    # 重写关闭
    window.mainloop()    # 显示主窗口
窗口创建和设置方法注释
window = tk.Tk()生成窗口

window.title('标题名')

修改窗口标题名字

window.geometry('500x650')

改变窗体大小,注意:(‘宽x高’)中x不是*
window.mainloop()   显示窗口

place()组件参数注释
x组件左上角的x坐标
y组件左上角的y坐标
anchor组件对齐方式
width组件的宽度
height 组件的高度

anchor参数值注释

n

s
w西
e
center中心
nw西北
ne东北
sw西南
se东南

tk核心组件注释说明
Label标签        用来显示文字或图片
Entry单行文字域用来收集键盘输入
Button按钮类似标签,但提供额外功能,比如鼠标/键盘事件

Label(根对象,[属性])注释
text标签名称
font字体(样式,大小)
bg背景颜色(标签颜色)
fg前景颜色(字体颜色)
width标签宽度
height标签高度
anchor锚选项,控制标签文本位置,参数同上

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值