Python -- Gui编程 -- Tkinter的使用 -- 基本控件
2014-05-04 16:36
781 查看
1.按钮
tkBtton.py
2.标签
tkLabel.py
3.单选框、复选框
tkCheck.py
4.单选框、复选框的平坦样式
tkRCButton.py
5.文本框
tkEntry.py
tkBtton.py
import tkinter root = tkinter.Tk() btn1 = tkinter.Button(root, anchor=tkinter.E,\ text='Button1', width=40, height=5) btn1.pack() btn2 = tkinter.Button(root, \ text='Button2', bg='blue') btn2.pack() btn3 = tkinter.Button(root, \ text='Button3', width=14, height=1) btn3.pack() btn4 = tkinter.Button(root, \ text='Button4', width=60, height=5, state=tkinter.DISABLED) btn4.pack() root.mainloop()
2.标签
tkLabel.py
import tkinter root = tkinter.Tk() lbl1 = tkinter.Label(root, anchor=tkinter.E, bg='blue', fg='red', text='Python', width=30, height=5) lbl1.pack() lbl2 = tkinter.Label(root, text='Python GUI\nTkinter', justify=tkinter.LEFT, width=30, height=5) lbl2.pack() lbl3 = tkinter.Label(root, text='Python GUI\nTkinter', justify=tkinter.RIGHT, width=30, height=5) lbl3.pack() lbl4 = tkinter.Label(root, text='Python GUI\nTkinter', justify=tkinter.CENTER, width=30, height=5) lbl4.pack() root.mainloop()
3.单选框、复选框
tkCheck.py
import tkinter root = tkinter.Tk() r = tkinter.StringVar() r.set('1') radio = tkinter.Radiobutton(root, variable=r, value='1', text='Radio1') radio.pack() radio = tkinter.Radiobutton(root, variable=r, value='2', text='Radio2') radio.pack() radio = tkinter.Radiobutton(root, variable=r, value='3', text='Radio3') radio.pack() radio = tkinter.Radiobutton(root, variable=r, value='4', text='Radio4') radio.pack() c = tkinter.IntVar() c.set(1) check = tkinter.Checkbutton(root, text='CheckButton', variable=c, onvalue=1, offvalue=2) check.pack() root.mainloop() print(r.get()) print(c.get())
4.单选框、复选框的平坦样式
tkRCButton.py
import tkinter root = tkinter.Tk() r = tkinter.StringVar() r.set('1') radio = tkinter.Radiobutton(root, variable=r, value='1', text='Radio1', indicatoron=0) radio.pack() radio = tkinter.Radiobutton(root, variable=r, value='2', text='Radio2', indicatoron=0) radio.pack() radio = tkinter.Radiobutton(root, variable=r, value='3', text='Radio3', indicatoron=0) radio.pack() radio = tkinter.Radiobutton(root, variable=r, value='4', text='Radio4', indicatoron=0) radio.pack() c = tkinter.IntVar() c.set(1) check = tkinter.Checkbutton(root, text='CheckButton', variable=c, onvalue=1, offvalue=2, indicatoron=0) check.pack() root.mainloop() print(r.get()) print(c.get())
5.文本框
tkEntry.py
import tkinter root = tkinter.Tk() entry1 = tkinter.Entry(root, show='*' ) entry1.pack() entry2 = tkinter.Entry(root, show='#', width='50') entry2.pack() entry3 = tkinter.Entry(root, bg='red', fg='blue') entry3.pack() entry4 = tkinter.Entry(root, selectbackground='red',\ selectforeground='gray') entry4.pack() entry5 = tkinter.Entry(root, state=tkinter.DISABLED) entry5.pack() edit1 = tkinter.Text(root, selectbackground='red', selectforeground='gray') edit1.pack() root.mainloop()
相关文章推荐
- Python -- Gui编程 -- Qt库的使用 -- 布局与基本控件
- Python -- Gui编程 -- Tkinter的使用 -- 对话框消息框
- Python -- Gui编程 -- Tkinter的使用 -- 对话框消息框
- Python -- Gui编程 -- Tkinter的使用 -- 菜单与画布
- python的GUI编程--wxpython学习(二)--基本控件和事件
- Python GUI编程 之Tkinter 基本参数
- Python中基于tkinter的GUI编程的基本概念与实例
- python GUI编程(Tkinter)简单使用
- 使用Tkinter做python的GUI编程
- Python:GUI之tkinter学习笔记1控件的介绍及使用
- python GUI编程(Tkinter)
- Python GUI编程(Tkinter)
- Python下用Tkinter进行GUI编程
- Python Tkinter GUI编程入门介绍
- Python GUI编程之 Tkinter 菜单
- python使用Tkinter编写GUI
- 鱼c笔记——Python的GUI编程(十七):Tkinter的标准对话框模块messagebox 、filedialog 和 colorchooser
- python的GUI编程(Tkinter库)(一)
- Python-GUI编程之 Tkinter 与 记事本实现心得
- python3.6 +tkinter GUI编程 实现界面化的文本处理工具