|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
刚学习 Tkinter ,做了一个生成随机颜色文字的小程序。
代码:
- # 导入 tkinter 和 random
- import tkinter as tk
- import random as r
- # rgb 颜色字符串
- COLOR = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'a', 'b', 'c', 'd', 'e', 'f']
- def change_color():
- color_string = '#'
- for i in range(6):
- color_string += r.choice(COLOR) # 生成随机rgb颜色
-
- # 显示 Label 文字
- text = tk.Label(root, fg=color_string, font=("楷体", 22), text="我爱 FishC!")
- text.pack(pady=2)
- root = tk.Tk()
- # 按钮
- btn = tk.Button(root, fg="#963963", text="生成随机颜色的 Label",
- command=change_color, font=("楷体", 15))
- btn.pack()
- tk.mainloop()
复制代码 |
|