当前位置:网站首页>GUI Graphical user interface programming example - color selection box
GUI Graphical user interface programming example - color selection box
2022-06-29 00:51:00 【Progress Xiaobai】
Thank you for opening Xiaobai's article
“ I hope you have made a little progress today , One step closer to a better life !”
Preface
The color selection box can help us set the background color 、 The foreground 、 Brush color 、 Font color, etc .
colorchooser It's simple , It provides a color interface that users can choose according to their own needs .
Basis for instance
from tkinter import *
from tkinter.colorchooser import *
root = Tk();root.geometry("400x150")
def test1():
s1 = askcolor(color="red", title=" Choose a background color ")
print(s1)
root.config(bg=s1[1])
Button(root,text=" Choose a background color ",command=test1).pack()
root.mainloop()
Turn on display color selection :

Select a good color to fill :

Enhanced instances , Free graffiti
import tkinter as tk
from tkinter.colorchooser import *
# Create a color selection function
def colorselect():
global color
colors = askcolor()
color = (int(colors[0][0]),int(colors[0][1]),int(colors[0][2]))
choosedcolor.set(str(color))
# Create drawing function
def paint(event):
x1, y1 = event.x, event.y
x2, y2 = event.x, event.y
w.create_oval(x1, y1, x2, y2, fill='#%02x%02x%02x' %color, outline='#%02x%02x%02x' %color) # Set color to colorchooser The chosen
root = tk.Tk()
color = (0,0,0)
choosedcolor = tk.StringVar()
choosedcolor.set(str(color)) # Set the initial color
tk.Label(root, text=" Free graffiti ").pack(padx=10,pady=10)
frame1 = tk.Frame(root)
tk.Button(frame1, text=" Choose a color ", relief='flat',command=colorselect).pack(side='left',padx=3, pady=3)
tk.Label(frame1, textvariable=choosedcolor).pack(side='left',padx=3, pady=3)
frame1.pack(anchor='w')
w = tk.Canvas(root, width=400, height=200)
w.pack()
w.bind("<B1-Motion>", paint) # Draw left mouse binding function
tk.Button(root, text=" Clear the screen ", command=(lambda a='all':w.delete(a))).pack(padx=5, pady=5)
root.mainloop()
Results show :

边栏推荐
- Daily question 1: the number of numbers in the array 2
- FATAL ERROR: Could not find ./ bin/my_ print_ Solutions to defaults
- Difference between applying for trademark in the name of individual and company
- EasyCVR集群版本替换成老数据库造成的服务崩溃是什么原因?
- [MCU club] design of blind water cup based on MCU [physical design]
- If you can play these four we media operation tools, the sideline income of 6000+ is very easy
- 统计字符串中不同回文子序列的个数
- 使用.Net驱动Jetson Nano的OLED显示屏
- Pinhole camera with added lens
- 戴口罩人脸数据集和戴口罩人脸生成方法
猜你喜欢

The magical zero knowledge proof can not only keep secrets, but also make others believe you!

最新Justnews主题源码6.0.1开心版+社交问答插件2.3.1+附教程

基于.NetCore开发博客项目 StarBlog - (13) 加入友情链接功能
UI高度自适应的修改方案

Getting started with SQL
![[image registration] improved SAR image registration based on sar-sift with matlab code](/img/69/4e78c6cef45b2e4d133222a4372e43.jpg)
[image registration] improved SAR image registration based on sar-sift with matlab code

Jbridge bridging frame technology for AI computing power landing

狼人杀休闲游戏微信小程序模板源码/微信小游戏源码

【leetcode】1719. Number of schemes for reconstructing a tree

Mask wearing face data set and mask wearing face generation method
随机推荐
cocoscreator动态切换SkeletonData实现骨骼更新
Daily question 1: remove elements
Getting started with SQL
Is it safe and reliable for qiniu school to help open a securities account? How to drive
Xuetong denies that the theft of QQ number is related to it: it has been reported; IPhone 14 is ready for mass production: four models are launched simultaneously; Simple and elegant software has long
旋轉接頭安裝使用注意事項
个人买同业存单基金选择什么证券公司开户好,更安全
[leetcode] 522. 最长特殊序列 II 暴力 + 双指针
养老年金险是理财产品吗?预期收益在哪看?
Jbridge bridging frame technology for AI computing power landing
Daily question 1: the number of numbers in the array 2
Résumé de Manon, 25 ans, diplômé en trois ans
Two ways to set up a single Nacos load balancing ribbon polling policy weight
Accessories and working process of machine vision system
最大路径和问题(摘樱桃问题)
分析框架——用户体验度量数据体系搭建
Nodejs installation and download
Daily question 1: the number of numbers in the array
FSS object storage how to access the Intranet
Successfully solved (machine learning data segmentation problem): modulenotfounderror: no module named 'sklearn cross_ validation‘