您的位置:首页 > 编程语言 > Python开发

python Tkinter 详解

2016-03-11 16:04 465 查看

!/usr/bin/python

-- coding: utf-8 --

import sys

from Tkinter import *

def result():

print(“The sum of 2+2 is “,2+2)

“””

win = Frame()

win.pack()

Label(win,text=”Click add to get the sum of quit to exit”).pack(side=TOP)

Button(win,text=”Add”,command=result).pack(side=LEFT)

Button(win,text=”Quit”,command=win.quit).pack(side=RIGHT)

win.mainloop()”“”

“”“state = ”

buttons=[]

def choose(i):

global state

state =i

for btn in buttons:

btn.deselect()

buttons[i].select()

root = Tk()

for i in range(4):

radio = Radiobutton(root,text=str(i),value=str(i),command=(lambda i =i:choose(i)))

radio.pack(side=BOTTOM)

buttons.append(radio)

root.mainloop()

print(“You chose the following number:”,state)”“”

“”“states=[]

def check(i):

states[i]= not states[i]

root = Tk()

for i in range(4):

test = Checkbutton(root,text=str(i),command=(lambda i =i:check(i)))

test.pack(side=TOP)

states.append(0)

root.mainloop()

print(states)”“”

popupper = (len(sys.argv)>1)

def dialog():

win = Toplevel()

Label(win,text=’Do You Always Do What You Are Told?’).pack()

Button(win,text=’Now click this one’,command=win.quit).pack()

if popupper:

win.focus_set()

win.grab_set()

win.wait_window()

print(‘You better obey me…’)

root = Tk()

Button(root,text=’Click Me’, command=dialog).pack()

root.mainloop()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: