From 9957956a82d35bb43635bbd08013329267dbf19d Mon Sep 17 00:00:00 2001 From: GOODPEN <12828106+goodpen@user.noreply.gitee.com> Date: Wed, 24 Jan 2024 09:15:41 +0000 Subject: [PATCH] =?UTF-8?q?add=20=E5=A5=BD=E7=8E=A9=E4=BD=86=E6=B2=A1?= =?UTF-8?q?=E4=BB=80=E4=B9=88=E7=94=A8=E4=BB=A3=E7=A0=81/=E5=BC=B9?= =?UTF-8?q?=E8=B7=B3=E7=AA=97=E5=8F=A3.py.=20=E4=B8=80=E4=B8=AA=E5=BC=B9?= =?UTF-8?q?=E8=B7=B3=E7=9A=84=E6=98=BE=E7=A4=BA=E6=96=87=E5=AD=97=E7=9A=84?= =?UTF-8?q?=E7=AA=97=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: GOODPEN <12828106+goodpen@user.noreply.gitee.com> --- ...71\350\267\263\347\252\227\345\217\243.py" | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 "\345\245\275\347\216\251\344\275\206\346\262\241\344\273\200\344\271\210\347\224\250\344\273\243\347\240\201/\345\274\271\350\267\263\347\252\227\345\217\243.py" diff --git "a/\345\245\275\347\216\251\344\275\206\346\262\241\344\273\200\344\271\210\347\224\250\344\273\243\347\240\201/\345\274\271\350\267\263\347\252\227\345\217\243.py" "b/\345\245\275\347\216\251\344\275\206\346\262\241\344\273\200\344\271\210\347\224\250\344\273\243\347\240\201/\345\274\271\350\267\263\347\252\227\345\217\243.py" new file mode 100644 index 0000000..0c85307 --- /dev/null +++ "b/\345\245\275\347\216\251\344\275\206\346\262\241\344\273\200\344\271\210\347\224\250\344\273\243\347\240\201/\345\274\271\350\267\263\347\252\227\345\217\243.py" @@ -0,0 +1,39 @@ +import tkinter as tk +import random as r + +root = tk.Tk() +screen_width = root.winfo_screenwidth() +screen_height = root.winfo_screenheight() +window_width = 400 +window_height = 300 + +x = (screen_width - window_width) // 2 +y = (screen_height - window_height) // 2 +root.geometry(f'{window_width}x{window_height}+{x}+{y}') +sw, sh = window_width, window_height +max1, max2 = sw - 20, sh - 70 +dxx, dyy = x, y +dx,dy = r.randint(3,8),r.randint(3,8) #弹跳速度 +tosn = "1+1=2" #输出文字 +nts = 100 #停留回合 +tos = "".join([i*nts for i in tosn]) +tosn = len(tosn)*nts +n = -1 + +def mov(): + global dxx, dyy, dx, dy, tos, n, tosn + if n==tosn-1: n=-1 + n +=1 + dxx += dx + dyy += dy + if dxx < 0 or dxx > screen_width - window_width: + dx = -dx + if dyy < 0 or dyy > screen_height - window_height: + dy = -dy + label = tk.Label(root, text=tos[n], font=("Arial", 24)) + label.place(relx=0.5, rely=0.5, anchor=tk.CENTER) + root.geometry(f"{50}x{80}+{dxx}+{dyy}") + root.after(5, mov) + +mov() +root.mainloop() -- Gitee