vue项目接口域名动态的获取方法
294
2022-08-27
PythonGUI编程之移动控件
移动小球
xx = 470yy = 350x = xx // 2y = yy // 2def tkinter3(): root = tk.Tk() r = 10 step = 10 root.geometry(str(xx)+'x'+str(yy)+'+250+250') root.resizable(False, False) root.title("手动移动小球") canvas = tk.Canvas(root, bg='white', height=700, width=700) canvas.pack() circle = canvas.create_oval(x + r, y + r, x - r, y - r, fill='red') def judge(x, y): if 0<= x <= xx and 0 <= y <= yy: return True else: return False def left(): global x, y x -= step if judge(x, y): canvas.move(circle, -step, 0) leftBtn = tk.Button(root, text="左移", width=8, height=1) leftBtn.config(command=left) leftBtn.place(x=75, y=320) def right(): global x, y x += step if judge(x, y): canvas.move(circle, step, 0) rightBtn = tk.Button(root, text="右移", width=8, height=1) rightBtn.config(command=right) rightBtn.place(x=150, y=320) def up(): global x, y y -= step if judge(x, y): canvas.move(circle, 0, -step) upBtn = tk.Button(root, text="上移", width=8, height=1) upBtn.config(command=up) upBtn.place(x=225, y=320) def down(): global x, y y += step if judge(x, y): canvas.move(circle, 0, step) downBtn = tk.Button(root, text="下移", width=8, height=1) downBtn.config(command=down) downBtn.place(x=300, y=320) root.mainloop()
移动标签
x = 0import tkinter as tkimport randomdef no3(): """ :return: """ root = tk.Tk() root.title("标签定制") root.geometry('320x160+250+250') root.resizable(False, False) v = tk.IntVar() tk.Label(root, text='标\n签\n定\n制', fg="red", width=15, height=5).place(x=10, y=80, anchor=tk.CENTER) values = [('红色', 0, 'red'), ('黄色', 1, 'yellow'), ('白色', 2, 'white'), ('绿色', 3, 'green'), ('随机色', 4, "#" + (''.join([hex(random.randint(17, 256)) for i in range(3)])).replace('0x', ''))] def callRB(): global x, t x = 160 for i in range(5): if v.get() == i: t = tk.Label(root, text='Python Tkinter', bg=values[i][2], width=15, height=3) t.place(x=x, y=80, anchor=tk.CENTER) t = 30 for i in range(5): r = tk.Radiobutton(root, text=values[i][0], font=("Arial", 12), command=callRB) r.config(variable=v, value=values[i][1]) r.place(x=t, y=20, anchor=tk.CENTER) t += 60 def left(): global x, t x -= 10 for i in range(5): if v.get() == i: t.destroy() t = tk.Label(root, text='Python Tkinter', bg=values[i][2], width=15, height=3) t.place(x=x, y=80, anchor=tk.CENTER) leftBtn = tk.Button(root, text="左移", width=8, height=1) leftBtn.config(command=left) leftBtn.place(x=75, y=120) def right(): global x, t x += 10 for i in range(5): if v.get() == i: t.destroy() t = tk.Label(root, text='Python Tkinter', bg=values[i][2], width=15, height=3) t.place(x=x, y=80, anchor=tk.CENTER) rightBtn = tk.Button(root, text="右移", width=8, height=1) rightBtn.config(command=right) rightBtn.place(x=175, y=120) root.mainloop()no3()
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~