python window窗口
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()
===========================
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | 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()
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
2013-12-04 C# 重新改变数组的长度