建立一个空白的页面框
import tkinter as tk window = tk.Tk() window.title("my first windows ") window.geometry('200x100') window.mainloop()
import tkinter as tk is_Hidden = False def hidden_me(): global is_Hidden if is_Hidden == False: is_Hidden = True var.set('click me and hidden') else: is_Hidden = False var.set('') window = tk.Tk() window.title("my first windows ") #define name for windows window.geometry('650x400')#the windows hiegh and weigth var= tk.StringVar() l=tk.Label(window,textvariable=var,bg='green',font=('Arial',12),width=25,height=4) l.pack() var1 = tk.StringVar() var1.set('hidden') b = tk.Button(window,textvariable=var1,width=12,height = 3,command = hidden_me) b.pack() window.mainloop()#the main loop
打包log rosoft Corporation。保留所有权利。 (venv) E:\build_code\text>pyinstaller -F ly.py 296 INFO: PyInstaller: 4.10 297 INFO: Python: 3.6.5 298 INFO: Platform: Windows-10-10.0.19041-SP0 299 INFO: wrote E:\build_code\text\ly.spec 306 INFO: UPX is not available. script 'E:\build_code\text\ly.py' not found (venv) E:\build_code\text>pyinstaller -F code.py 122 INFO: PyInstaller: 4.10 123 INFO: Python: 3.6.5 123 INFO: Platform: Windows-10-10.0.19041-SP0 126 INFO: wrote E:\build_code\text\code.spec 131 INFO: UPX is not available. script 'E:\build_code\text\code.py' not found (venv) E:\build_code\text>pyinstaller -F code 132 INFO: PyInstaller: 4.10 132 INFO: Python: 3.6.5 133 INFO: Platform: Windows-10-10.0.19041-SP0 134 INFO: wrote E:\build_code\text\code.spec 140 INFO: UPX is not available. 151 INFO: Extending PYTHONPATH with paths ['E:\\build_code\\text'] 515 INFO: checking Analysis 515 INFO: Building Analysis because Analysis-00.toc is non existent 515 INFO: Initializing module dependency graph... 518 INFO: Caching module graph hooks... 551 INFO: Analyzing base_library.zip ... 7226 INFO: Caching module dependency graph... 7430 INFO: running Analysis Analysis-00.toc 7507 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable required by e:\python3.5.6\python.exe 7903 INFO: Analyzing E:\build_code\text\code 8085 INFO: Processing module hooks... 8086 INFO: Loading module hook 'hook-difflib.py' from 'e:\\python3.5.6\\lib\\site-packages\\PyInstaller\\hooks'... 8087 INFO: Loading module hook 'hook-encodings.py' from 'e:\\python3.5.6\\lib\\site-packages\\PyInstaller\\hooks'... 8207 INFO: Loading module hook 'hook-heapq.py' from 'e:\\python3.5.6\\lib\\site-packages\\PyInstaller\\hooks'... 8209 INFO: Loading module hook 'hook-pickle.py' from 'e:\\python3.5.6\\lib\\site-packages\\PyInstaller\\hooks'... 8210 INFO: Loading module hook 'hook-xml.py' from 'e:\\python3.5.6\\lib\\site-packages\\PyInstaller\\hooks'... 8620 INFO: Loading module hook 'hook-_tkinter.py' from 'e:\\python3.5.6\\lib\\site-packages\\PyInstaller\\hooks'... 8810 INFO: checking Tree 8810 INFO: Building Tree because Tree-00.toc is non existent 8810 INFO: Building Tree Tree-00.toc 8857 INFO: checking Tree 8857 INFO: Building Tree because Tree-01.toc is non existent 8857 INFO: Building Tree Tree-01.toc 8959 INFO: checking Tree 8960 INFO: Building Tree because Tree-02.toc is non existent 8960 INFO: Building Tree Tree-02.toc 8979 INFO: Looking for ctypes DLLs 8979 INFO: Analyzing run-time hooks ... 8982 INFO: Including run-time hook 'e:\\python3.5.6\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_subprocess.py' 8984 INFO: Including run-time hook 'e:\\python3.5.6\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgutil.py' 8987 INFO: Including run-time hook 'e:\\python3.5.6\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_inspect.py' 8991 INFO: Including run-time hook 'e:\\python3.5.6\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth__tkinter.py' 9000 INFO: Looking for dynamic libraries 9495 INFO: Looking for eggs 9495 INFO: Using Python library e:\python3.5.6\python36.dll 9495 INFO: Found binding redirects: [] 9514 INFO: Warnings written to E:\build_code\text\build\code\warn-code.txt 9567 INFO: Graph cross-reference written to E:\build_code\text\build\code\xref-code.html 9625 INFO: checking PYZ 9625 INFO: Building PYZ because PYZ-00.toc is non existent 9626 INFO: Building PYZ (ZlibArchive) E:\build_code\text\build\code\PYZ-00.pyz 10163 INFO: Building PYZ (ZlibArchive) E:\build_code\text\build\code\PYZ-00.pyz completed successfully. 10181 INFO: checking PKG 10181 INFO: Building PKG because PKG-00.toc is non existent 10181 INFO: Building PKG (CArchive) code.pkg 15398 INFO: Building PKG (CArchive) code.pkg completed successfully. 15427 INFO: Bootloader e:\python3.5.6\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe 15428 INFO: checking EXE 15428 INFO: Building EXE because EXE-00.toc is non existent 15428 INFO: Building EXE from EXE-00.toc 15429 INFO: Copying bootloader EXE to E:\build_code\text\dist\code.exe.notanexecutable 15652 INFO: Copying icon to EXE 15653 INFO: Copying icons from ['e:\\python3.5.6\\lib\\site-packages\\PyInstaller\\bootloader\\images\\icon-console.ico'] 15752 INFO: Writing RT_GROUP_ICON 0 resource with 104 bytes 15752 INFO: Writing RT_ICON 1 resource with 3752 bytes 15753 INFO: Writing RT_ICON 2 resource with 2216 bytes 15753 INFO: Writing RT_ICON 3 resource with 1384 bytes 15753 INFO: Writing RT_ICON 4 resource with 37019 bytes 15753 INFO: Writing RT_ICON 5 resource with 9640 bytes 15754 INFO: Writing RT_ICON 6 resource with 4264 bytes 15754 INFO: Writing RT_ICON 7 resource with 1128 bytes 15756 INFO: Copying 0 resources to EXE 15757 INFO: Emedding manifest in EXE 15758 INFO: Updating manifest in E:\build_code\text\dist\code.exe.notanexecutable 15850 INFO: Updating resource type 24 name 1 language 0 15853 INFO: Appending PKG archive to EXE 21200 INFO: Building EXE from EXE-00.toc completed successfully. (venv) E:\build_code\text>
#绑定鼠标点击事件 from tkinter import * #import tkinter as tk root = Tk() def callback(event): print ("clicked at",event.x,event.y) frame = Frame(root,width=100,height=100) frame.bind("<Button-1>",callback) frame.pack() root.mainloop()