当前位置:网站首页>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 :

边栏推荐
- Sampling with VerilogA module
- 手下两个应届生:一个踏实喜欢加班,一个技术强挑活,怎么选??
- [UVM] my main_ Why can't the case exit when the phase runs out? Too unreasonable!
- [MCU club] design of classroom number detection based on MCU [simulation design]
- 搭建单机 nacos 负载均衡ribbon 轮询策略 权重2种方式
- Basic use of Chrome browser
- It is safer for individuals to choose a securities company to open an account when buying interbank certificates of deposit
- What is redis
- Nodejs安装和下载
- 光纤滑环价格过高的原因
猜你喜欢
![[image detection] recognition of the front and back of a coin based on texture features with matlab code attached](/img/84/0a364adcd373cc40c9bc7b70d50f93.jpg)
[image detection] recognition of the front and back of a coin based on texture features with matlab code attached

Install MySQL on Windows platform (with Navicat premium 12 "using" tutorial)

Daily question 1: missing numbers
![[staff] accent mark, gradually stronger mark and gradually weaker mark](/img/5d/5738bd5503d7ed0621932f901c2e8d.jpg)
[staff] accent mark, gradually stronger mark and gradually weaker mark

Difference between applying for trademark in the name of individual and company
![[image detection] line recognition based on Hough transform (fitting angle bisector) with matlab code](/img/29/a3dc68ebc958ff96c3d8cc771a84f1.jpg)
[image detection] line recognition based on Hough transform (fitting angle bisector) with matlab code

Matrix compression

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

EasyCVR集群版本替换成老数据库造成的服务崩溃是什么原因?

Ensemble de données sur les visages masqués et méthode de génération des visages masqués
随机推荐
What is redis
Précautions d'installation et d'utilisation des joints rotatifs
[image registration] improved SAR image registration based on sar-sift with matlab code
Blazor University (34) forms - get form status
Es6:let, const, arrow functions
Mapbox GL loading local publishing DEM data
使用.Net驱动Jetson Nano的OLED显示屏
同期群分析是什么?教你用 SQL 来搞定
Baidu online disk login verification prompt: unable to access this page, or the QR code display fails, the pop-up window shows: unable to access this page, ensure the web address....
Redis常用命令手册
基于.NetCore开发博客项目 StarBlog - (13) 加入友情链接功能
最大路径和问题(摘樱桃问题)
卷绕工艺与叠片工艺的对比
启牛学堂帮忙开证券账户是安全靠谱的吗?个人如何开
Notes on the infrastructure of large websites
Drawing ECG curve with WPF
Accessories and working process of machine vision system
Reference materials in the process of using Excel
盘点 6 月 yyds 的开源项目!
养老年金险是理财产品吗?预期收益在哪看?