'''GUI'''
'''创建窗口,并显示'''
# import tkinter
#
# win = tkinter.Tk()#窗体
# win.mainloop()#进入消息循环
'''修改窗口名字'''
# import tkinter
# win = tkinter.Tk(className='标题')
# # win.wm_title('标题')#设置方法二
# win.mainloop()
'''在窗口加入文本标签'''
# import tkinter
# win = tkinter.Tk(className='标题')
#
# lable = tkinter.Label()
# lable['text']='文本'
# lable.pack()
#
# win.mainloop()
'''在窗体添加按钮'''
# import tkinter
# win = tkinter.Tk(className='标题')
#
# button = tkinter.Button()
# button['text']='我是按钮'
# button.pack()
#
# win.mainloop()
'''添加按钮点击效果'''
# import tkinter
# win = tkinter.Tk(className='标题')
#
# def click():
# print('点击了')
#
# button = tkinter.Button()
# button['text']='点击按钮'
# button['command']=click
# button.pack()
#
# button=tkinter.Button(text='按钮',command=click)
# button.pack()
#
#
# win.mainloop()
'''设置窗体大小'''
# import tkinter
# win = tkinter.Tk()
# win.geometry('300x400')
# win.mainloop()
''' 添加按钮,设置颜色'''
# import tkinter
# win = tkinter.Tk()
# frame = tkinter.Frame(win)
# frame.pack()
# def say_hi():
# print('say hi')
# tkinter.Button(frame,text='Quite',fg='red',command=frame.quit).pack(side=tkinter.LEFT)
# tkinter.Button(frame,text='hello',command=say_hi).pack(side=tkinter.LEFT)
#
# win.mainloop()
'-----------------------------------------------------------------------------------------------------------------------'
# import tkinter
# class App:
# def __init__(self,master):
# #构造函数 传入父组件master,创建一个Fram组件并显示
# frame = tkinter.Frame(master)
# frame.pack()
# #创建两个按钮,并作为frame的一部分
# self.button=tkinter.Button(frame,text='Quite',fg='red',command=frame.quit())
# self.button.pack(side=tkinter.LEFT)#此处设置side为LEFT,表示将其放置在frame剩余空间的左边
# self.button1 = tkinter.Button(frame,text='hello',command=self.say_hi)
# self.button1.pack(side=tkinter.LEFT)
#
# def say_hi(self):
# print('say_hi')
#
#
# win = tkinter.Tk()
# app = App(win)
#
# # tkinter.Label(win,text='text').pack()
# win.mainloop()
'''添加可编辑文本'''
# import tkinter
# #定义一个函数,点击按钮调用
# def on_click():
# lable['text']='no way!'
#
# win = tkinter.Tk(className='标题')
#
# #加上标签
# lable = tkinter.Label(win)
# lable['text']='playing'
# lable.pack()
# #按钮
# button = tkinter.Button(text='ok',command=on_click)
# button.pack()
# text = tkinter.StringVar()
# text.set('how ?')
# entry = tkinter.Entry(win,textvariable=text).pack()
#
# win.mainloop()
'''下拉菜单'''
# import tkinter
#
# win = tkinter.Tk()
#
# def hello():
# print('hello')
# def about():
# print('about')
#
# menubar = tkinter.Menu(win)
#
# #创建下拉菜单File,然后将其加入到顶级菜单栏
# filemenu = tkinter.Menu(menubar,tearoff=0)
# filemenu.add_command(label='Open',command=hello)
# filemenu.add_command(label='Save',command=hello)
# filemenu.add_separator()
# filemenu.add_command(label='Exit',command=win.quit)
#
# menubar.add_cascade(label='File',menu=filemenu)
#
# #创建下拉菜单Edit
# editmenu = tkinter.Menu(menubar,tearoff=0)
#
# editmenu.add_command(label='Cut',command=hello)
# editmenu.add_command(label='Copy',command=hello)
# editmenu.add_command(label='Paste',command=hello)
#
# menubar.add_cascade(label='Edit',menu=editmenu)
#
# #下拉菜单Help
# helpmenu = tkinter.Menu(menubar,tearoff=0)
#
# helpmenu.add_command(label='About',command=about)
#
# menubar.add_cascade(label='Help',menu=helpmenu)
#
# win.config(menu=menubar)#显示菜单
# win.mainloop()
'''按钮在窗口中显示'''
# import tkinter
#
# win = tkinter.Tk()
#
# def hello():
# print('hello')
#
# def about():
# print('about')
#
# def help():
# w = tkinter.Label(win,text='显示文本:我是文本\n在窗口显示我')
# w.pack(side=tkinter.TOP)
#
# menubar = tkinter.Menu(win)
#
# #创建下拉菜单File,加入顶级菜单
# filemenu = tkinter.Menu(menubar,tearoff=0)
# filemenu.add_command(label='Open',command=hello)
# filemenu.add_command(label='Save',command=hello)
# filemenu.add_separator()
# filemenu.add_command(label='Exit',command=win.quit)
#
# menubar.add_cascade(label='File',menu=filemenu)
# #Edit下拉菜单
# editmenu = tkinter.Menu(menubar,tearoff=0)
# editmenu.add_command(label='Cut',command=hello)
# editmenu.add_command(label='Copy',command=hello)
# editmenu.add_command(label='Paste',command=hello)
# menubar.add_cascade(label='Edit',menu=editmenu)
#
# #下拉菜单Help
# helpmenu = tkinter.Menu(menubar,tearoff=0)
# helpmenu.add_command(label='About',command=about)
# helpmenu.add_command(label='Help',command=help)
# menubar.add_cascade(label='Help',menu=helpmenu)
#
# win.config(menu=menubar)
#
# win.mainloop()
'''改变背景颜色'''
# import tkinter
#
# win = tkinter.Tk()
# tkinter.Label(win,text='lable1',bg='red').pack()
# tkinter.Label(win,text='lable2',bg='blue').pack()
# tkinter.Label(win,text='lable3',bg='green').pack()
#
# win.mainloop()
'''
pack常用的属性
属性名 属性简析 取值 取值说明
------------------------------------------------------------------------------------------------------------------------
fill 设置填充 X|Y|BOTN|NONE fill=X水平方向填充
fill=Y垂直方向填充
fill=BOTH水平和垂直都填充
fill=NONE不填充
------------------------------------------------------------------------------------------------------------------------
expand 设置组件是否展开,
当值为YES时,
side选项无效。 YES 、NO(1、0) expand=YES expand=NO
组件显示在父容器中心位置;
若fill选项为BOTH,
则填充父组件的剩余空间。
默认为不展开
------------------------------------------------------------------------------------------------------------------------
side 设置组件的对齐方式 LEFT、TOP、RIGHT、BOTTOM 值为左、上、右、下
------------------------------------------------------------------------------------------------------------------------
ipadx、ipady 设置x方向(或者y方向)
内部间隙(子组件之间的间隔) 可设置数值,默认是0 非负整数,单位为像素
------------------------------------------------------------------------------------------------------------------------
padx、pady 设置x方向(或者y方向)
外部间隙(与之并列的组件之间的间隔) 可设置数值,默认是0 非负整数,单位为像素
------------------------------------------------------------------------------------------------------------------------
anchor 锚选项,
当可用空间大于所需求的尺寸时, N、E、S、W、NW、NE、
决定组件被放置于容器的何处 SW、SE、CENTER(默认值为CENTER) 表示八个方向以及中心
------------------------------------------------------------------------------------------------------------------------
'''
网友评论