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()
================================
 import Tkinter  as tk

 def get_screen_size(window):
return window.winfo_screenwidth(),window.winfo_screenheight() def get_window_size(window):
return window.winfo_reqwidth(),window.winfo_reqheight() def center_window(root, width, height):
screenwidth = root.winfo_screenwidth()
screenheight = root.winfo_screenheight()
size = '%dx%d+%d+%d' % (width, height, (screenwidth - width)/2, (screenheight - height)/2)
print(size)
root.geometry(size) root = tk.Tk()
root.title('测试窗口')
center_window(root, 300, 240)
root.maxsize(600, 400)
root.minsize(300, 240)
Tkinter.Label(root, relief = tk.FLAT, text = '屏幕大小(%sx%s)\n窗口大小(%sx%s)' % (get_screen_size(root) + get_window_size(root))).pack(expand = tk.YES)
tk.mainloop()

 

===========================

from Tkinter import *

class CanvasDemo:
def __init__(self):
window = Tk()
window.title("CanvasDemo") self.canvas = Canvas(window, width = 200, height = 100, bg = "White")
self.canvas.pack() frame = Frame(window)
frame.pack() btRectangle = Button(frame, text = "长方形", command = self.displayRect)
btOval = Button(frame, text="椭 圆", command=self.displayOval)
btArc = Button(frame, text = "圆 弧", command = self.displayArc)
btPolygon = Button(frame, text="多边形", command=self.displayPolygon)
btLine = Button(frame, text=" 线 ", command=self.displayLine)
btString = Button(frame, text="文 字", command=self.displayString)
btClear = Button(frame, text="清 空", command=self.clearCanvas) btRectangle.grid(row = 1, column = 1)
btOval.grid(row=1, column=2)
btArc.grid(row=1, column=3)
btPolygon.grid(row=1, column=4)
btLine.grid(row=1, column=5)
btString.grid(row=1, column=6)
btClear.grid(row=1, column=7) window.mainloop() def displayRect(self):
self.canvas.create_rectangle(10, 10, 190, 90, tags = "rect")
def displayOval(self):
self.canvas.create_oval(10, 10, 190, 90, tags = "oval", fill = "red")
def displayArc(self):
self.canvas.create_arc(10, 10, 190, 90, start = -90, extent = 90, width = 5, fill = "red", tags = "arc")
def displayPolygon(self):
self.canvas.create_polygon(10, 10, 190, 90, 30, 50, tags = "polygon")
def displayLine(self):
self.canvas.create_line(10, 10, 190, 90, fill = 'red', tags = "line")
self.canvas.create_line(10, 90, 190, 10, width = 9, arrow = "last", activefill = "blue", tags = "line")
def displayString(self):
self.canvas.create_text(60, 40, text = "Hi,i am a string", font = "Tine 10 bold underline", tags = "string")
def clearCanvas(self):
self.canvas.delete("rect", "oval", "arc", "polygon", "line", "string") CanvasDemo()

  

import Tkinter as tk      #引入Tkinter模块
window = tk.Tk() def checkPassword(): #密码接收与检验
password = "Pass"
enteredPassword = passwordEntry.get()
if password == enteredPassword:
confirmLabel.config(text="Correct")
else:
confirmLabel.config(text="Incorrrect") passwordLabel = tk.Label(window,text="Password:") #创建密码标签控件与密码输入框
passwordEntry = tk.Entry(window,show="*") button = tk.Button(window,text="Enter",command=checkPassword) #添加按钮
confirmLabel = tk.Label(window)
#控件布局
passwordLabel.pack()
passwordEntry.pack()
button.pack()
confirmLabel.pack() window.mainloop()

最新文章

  1. 构建自己的 Linux 发行版
  2. (转)sql的join图解
  3. Sparse Filtering 学习笔记(二)好特征的刻画
  4. Ubuntu 新建swap分区及启用
  5. 【面经】【转】C程序的内存布局
  6. JavaScript学习之窗口
  7. Linux命令(2)-rm删除文件
  8. 深入浅出ES6(十三):类 Class
  9. Windows Live Writer 完成开源并推出开源分支
  10. Trie树(字典树)
  11. PHP全选择删除功能
  12. 浅析CQRS的应用部署
  13. Duilib第一步(I)-简介与环境搭建
  14. Linux文件与目录管理 - ls, cp, mv
  15. SAP MM 根据采购订单反查采购申请?
  16. python 第二百零八天 ----算法相关
  17. windows连接服务端的域名正常,linux却不通,(针对于负载均衡后端节点设置)
  18. Java容器解析系列(2) 具体化的第一步——Collection到AbstractCollection
  19. 【Java基本功】一文了解Java中继承、封装、多态的细节
  20. Java程序员面试中的多线程问题1

热门文章

  1. SetCurrentCellAddressCore 函数的可重入调用
  2. DRF 有无外键操作实例
  3. TCP、UDP、HTTP、HTTPS之间的区别
  4. Python——函数&作用域
  5. MySQL数据库机房裁撤问题总结
  6. WIN8输入法的问题
  7. jvm整理
  8. 《少年先疯队》第八次团队作业:Alpha冲刺1-5
  9. 帝国CMS熊掌号数据主动推送插件【原创】
  10. python_面向对象——动态创建类和isinstance和issubclass方法