赞
踩
from tkinter import *
root = Tk()
Entry(root, text='input your text here').pack() # text毫无作用
root.mainloop()
from tkinter import *
root = Tk()
e = StringVar()
entry = Entry(root, textvariable=e)
e.set('entry your text here') # 设定初始文本
entry.pack()
root.mainloop()
from tkinter import *
root = Tk()
e = StringVar()
entry = Entry(root, textvariable=e, state='readonly')
e.set('entry your text here')
entry.pack()
root.mainloop()
from tkinter import *
root = Tk()
Label(root, text='input your password below').pack()
e = StringVar()
entry = Entry(root, textvariable=e, show='*')
entry.pack()
root.mainloop()
多选按钮,可以表示两种状态:On或Off,可以设置回调函数,每当点击此按钮时回调函数被调用。
from tkinter import *
root = Tk()
Checkbutton(root, text='python').pack()
root.mainloop()
from tkinter import *
def callback():
print('checked this button')
root = Tk()
Checkbutton(root, text='python', command=callback).pack()
root.mainloop()
from tkinter import *
def callback():
v.set('change checkbutton')
root = Tk()
v = StringVar()
v.set('check button')
Checkbutton(root, text='python', command=callback, textvariable=v).pack()
root.mainloop()
from tkinter import *
def callback():
print(v.get())
v.set(v.get())
root = Tk()
v = IntVar()
v.set('check button')
Checkbutton(root, text='python', command=callback, variable=v, textvariable=v).pack()
root.mainloop()
from tkinter import *
def callback():
print(v.get())
root = Tk()
v = StringVar()
v.set('check button')
Checkbutton(root, text='python', command=callback, variable=v, onvalue='python', offvalue='tkinter').pack()
root.mainloop()
单选按钮
from tkinter import *
root = Tk()
Radiobutton(root, text='python').pack()
Radiobutton(root, text='tkinter').pack()
Radiobutton(root, text='widget').pack()
root.mainloop()
from tkinter import *
root = Tk()
v = IntVar()
v.set(1)
for i in range(3):
Radiobutton(root, variable=v, text='python', value=i).pack()
root.mainloop()
from tkinter import *
root = Tk()
vLang = IntVar()
vOS = IntVar()
vLang.set(1)
vOS.set(2)
for v in [vLang,vOS]:
for i in range(3):
Radiobutton(root, variable=v, value=i, text='python' + str(i)).pack()
root.mainloop()
from tkinter import *
root = Tk()
v = IntVar()
v.set(1)
for i in range(3):
Radiobutton(root, variable=v, value=1, text='python' + str(i)).pack()
for i in range(3):
Radiobutton(root, variable=v, value=i, text='python' + str(2 + i)).pack()
root.mainloop()
from tkinter import * def r1(): print('call r1') def r2(): print('call r2' ) def r3(): print('call r3') def r4(): print('call r4' ) i = 0 root = Tk() v = IntVar() v.set(0) for r in [r1, r2, r3, r4]: Radiobutton(root, variable=v, text='radio button', value=i, command=r).pack() Radiobutton(root, variable=v, text='radio button', value=i, command=r).pack() i += 1 root.mainloop()
from tkinter import *
root = Tk()
v = IntVar()
v.set(1)
for i in range(3):
Radiobutton(root, variable=v, indicatoron=0, text='python & tkinter', value=i).pack()
root.mainloop()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。