劉任昌python全域變數global和判斷if
from tkinter import * #或者import tkinter as tk
import math#輸入數學MATH函式庫
tk = Tk() #建構視窗名為tk
tk.geometry('1200x400')#視窗 寬1200像素
tk.title("劉任昌python tkinter三角函數if_else判斷")
canvas = Canvas(tk, width=1200, height=400, bg='PINK')
canvas.grid(row=0,column=0,padx=5,pady=5,columnspan=3)
delay=3 # milliseconds, 1/1000秒
x1,y1,z1=0,200,10#python特徵,多變數=對等值
h=190 #上下範圍,相當於數學1到-1
def LH():
global x1, y1, z1#global全球,local當地
x2 = x1 + 1 #換到下個+1
y2=200 - h*math.sin(0.02*x2)
z2=200 - h*math.cos(0.02*x2)
L1=canvas.create_line(x1,y1,x2,y2,fill='BLUE',width=10)
L2=canvas.create_line(x1,z1,x2,z2,fill='yellow',width=10)
if (x2 < 1200): #沒有超過, 記得將 "小於" 改成運算
x1,y1,z1=x2,y2,z2#下一個起點是現在終點
canvas.after(delay,LH)#每隔delay執行
else:
canvas.delete("all")
x1,y1,z1=0,200,10#下一個起點是回到原點
canvas.after(delay,LH)#return沒你的事,滾回你老家
LH() #執行LauHou老猴
tk.mainloop()
放置在最前面的style
<STYLE> PRE{BORDER: 3PX SOLID GREEN} H1{BOERDER: 10PX SOLID GREEN;BACKGROUND:BLACK;COLOR:WHITE;TEXT-ALIGN:CENTER;PADDING:5PX;} </STYLE>mainloop的說明
tkinter 是 Python 的內建函式庫,只要 import tkinter 就能使用,下方的程式碼執行後,會使用 Tk() 方法建立 tkinter 視窗物件,接著使用 mainloop() 將其放在主迴圈中一直執行,直到使用者關閉該視窗才會停止運作。 https://steam.oxxostudio.tw/category/python/tkinter/start.html財金程式設計615拷貝mainloop的資訊
嵌入標題的完整指令一定要在HTML模式下
<h1>財金程式設計615拷貝mainloop的資訊</h1><iframe width="560" height="315" src="https://www.youtube.com/embed/qTjqgn2-Cgw?si=1tXHg4Eh1xK2zEGn" title=YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
在撰寫模式(偷懶)價貼上GOOGLE AI
mainloop(主循環)是電腦程式中一個核心概念,指程式持續運行、不斷接收和處理事件的無限循環,常見於圖形用戶界面(GUI) 應用程序,如Python 的Tkinter 庫中,它啟動了事件監聽(點擊、按鍵等)、事件處理(執行函數)和界面更新的流程,使程序保持響應,直到用戶關閉窗口。 核心功能
- 事件監聽: 等待使用者輸入、系統訊息或視窗事件。
- 事件處理: 捕捉事件,並呼叫對應的處理函數(回呼函數)。
- 介面更新: 根據事件處理結果刷新介面。
- 生命週期控制: 保持程式運行,直到明確退出或關閉視窗。
在不同框架中的應用
- Python Tkinter : tkinter .Tk().mainloop()` 是啟動GUI 的關鍵,讓視窗回應使用者操作。
- Godot Engine :
MainLoop是遊戲循環的抽象基類,由SceneTree實現,控制遊戲運行流程。
總結
mainloop就像應用程式的“心臟”,源源不斷地接收和處理外部訊號,確保程式能夠與使用者互動並正常運作。
https://wu-hanlin.blogspot.com/2025/12/pythonglobalif.html
回覆刪除https://zxc100003.blogspot.com/2025/12/globalif.html
回覆刪除https://yehkotang.blogspot.com/2025/12/pythonglobalif.html
回覆刪除https://chenweikaipyhone.blogspot.com/2025/12/pythonglobalif.html
回覆刪除https://hsiashenkai.blogspot.com/2025/12/pythonglobalif.html
回覆刪除https://f960530.blogspot.com/2025/12/pythonglobalif.html
回覆刪除https://qiujixuan.blogspot.com/2025/12/pythonglobalif.html
回覆刪除https://bhhjnf.blogspot.com/2025/12/from-tkinter-import-import-tkinter-as.html
回覆刪除https://ry6uuigojkmrltihu09fut.blogspot.com/2025/12/globalif.html
回覆刪除https://jiajinglai38.blogspot.com/2025/12/pythonglobalif.html
回覆刪除https://hsieh02.blogspot.com/2025/12/pythonglobalif.html
回覆刪除https://linyh960303.blogspot.com/2025/12/pythonglobalif.html
回覆刪除作者已經移除這則留言。
回覆刪除https://gmail0930.blogspot.com/2025/12/from-tkinter-import-import-tkinter-as.html
回覆刪除https://quyznn07.blogspot.com/2025/12/from-tkinter-import-import-tkinter-as.html
回覆刪除https://penny0610.blogspot.com/2025/12/pythonglobalif.html
回覆刪除https://andy20051217.blogspot.com/2025/12/pythonglobalif.html
回覆刪除https://santreepay.blogspot.com/2025/12/pythonglobalif.html
回覆刪除https://qianweixin.blogspot.com/2025/12/from-tkinter-import-import-tkinter-as.html
回覆刪除https://ddjcfiv.blogspot.com/2025/12/pythonglpbalif.html
回覆刪除https://crystal03280328.blogspot.com/2025/12/pythonglobalif.html
回覆刪除https://tientien98084.blogspot.com/2025/12/pythonglobalif.html
回覆刪除https://16pyoyo.blogspot.com/2025/12/pythonglobalif.html
回覆刪除https://caipeizhen.blogspot.com/2025/12/pythonglobalif.html
回覆刪除https://z828253084.blogspot.com/2025/12/blog-post.html
回覆刪除https://rui960104.blogspot.com/2025/12/globalif.html
回覆刪除https://biiken19071999.blogspot.com/2025/12/pythongobalif.html
回覆刪除https://chuthithu.blogspot.com/2025/12/pythongobalif.html
回覆刪除https://tsaiziytang.blogspot.com/2025/12/pythonglobalif.html
回覆刪除https://chenyouhong.blogspot.com/2025/12/pythonglobalif.html
回覆刪除https://hidhfcaha.blogspot.com/2025/12/pythonglobalif.html
回覆刪除https://linpinxuan06.blogspot.com/2025/12/pythonglobalif.html
回覆刪除https://yininglee96.blogspot.com/2025/12/from-tkinter-import-import-tkinter-as_7.html
回覆刪除https://zhanyujin.blogspot.com/2025/12/pythonglobalif.html
回覆刪除https://eastyi.blogspot.com/2025/12/pythonglobalif.html
回覆刪除https://hodkrbcjlkwsnd.blogspot.com/2025/12/pythonglobalif.html
回覆刪除https://zhangzhixuan2006.blogspot.com/2025/12/pythonglobalif.html
回覆刪除https://chunyuan14.blogspot.com/2025/12/pythonglobalif.html
回覆刪除https://zhengword.blogspot.com/2025/12/pythonglobalif-12-07-2025.html
回覆刪除https://wutsungchuan.blogspot.com/2025/12/pythonglobalif.html
回覆刪除https://yojheyu.blogspot.com/2025/12/pythonglobalif.html
回覆刪除https://xieyouting.blogspot.com/2025/12/pythonglobalif.html
回覆刪除https://hejaijun.blogspot.com/2025/12/pythonglobalif.html
回覆刪除https://chiiu-shih-min.blogspot.com/2025/12/from-tkinter-import-import-tkinter-as.html
回覆刪除https://jasonaq4746.blogspot.com/2025/12/pythonglobalif.html
回覆刪除https://qxrlybn.blogspot.com/2025/12/pythonglobalif.html
回覆刪除作者已經移除這則留言。
回覆刪除https://umyjmyju45545.blogspot.com/2025/12/pythonglobalif.html
回覆刪除https://aster1210.blogspot.com/2025/12/blog-post.html
回覆刪除https://zhoutzuhsin.blogspot.com/2025/12/math.html
回覆刪除https://16pyoyo.blogspot.com/2025/12/pythonglobalif_14.html
回覆刪除https://tientien98084.blogspot.com/2025/12/pythonglobali.html
回覆刪除https://chenyunxi.blogspot.com/2025/12/blog-post.html
回覆刪除作者已經移除這則留言。
回覆刪除https://wangtingyiprincess.blogspot.com/2025/12/pythonglobalif.html
回覆刪除