python Tkinter 詳解

!/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()

發佈了39 篇原創文章 · 獲贊 8 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章