from Tkinter import *
root=Tk()
root.title('我是root窗口!')
L=Label(root,text='我属于root')
L.pack()

f=Toplevel(root,width=30,height=20)
f.title('我是toplevel')
Lf=Label(f,text='我是toplevel')
Lf.pack()

root.mainloop()

==============================
from Tkinter import *
time1=0
time2=0
def xin1():
    global t,c1,time1
    if time1%2==0:
        time1+=1
        t['text']='西瓜被选中'
    else:
        time1+=1
        t['text']='西瓜被取消'
def xin2():
    global t,c2,time2
    if time2%2==0:
        time2+=1
        t['text']='芒果被选中'
    else:
        time2+=1
        t['text']='芒果被取消'
root=Tk()
c1=Checkbutton(root,text='西瓜',command=xin1)
c1.pack()
c2=Checkbutton(root,text='芒果',command=xin2)
c2.pack()
t=Label(root,text='')
t.pack()
root.mainloop()
================================
 1 import Tkinter  as tk
 2
 3
 4 def get_screen_size(window):
 5     return window.winfo_screenwidth(),window.winfo_screenheight()
 6
 7 def get_window_size(window):
 8     return window.winfo_reqwidth(),window.winfo_reqheight()
 9
10 def center_window(root, width, height):
11     screenwidth = root.winfo_screenwidth()
12     screenheight = root.winfo_screenheight()
13     size = '%dx%d+%d+%d' % (width, height, (screenwidth - width)/2, (screenheight - height)/2)
14     print(size)
15     root.geometry(size)
16
17 root = tk.Tk()
18 root.title('测试窗口')
19 center_window(root, 300, 240)
20 root.maxsize(600, 400)
21 root.minsize(300, 240)
22 Tkinter.Label(root, relief = tk.FLAT, text = '屏幕大小(%sx%s)\n窗口大小(%sx%s)' % (get_screen_size(root) + get_window_size(root))).pack(expand = tk.YES)
23 tk.mainloop()
 
12-14 20:01
查看更多