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

边栏推荐
- [image detection] recognition of the front and back of a coin based on texture features with matlab code attached
- 旋轉接頭安裝使用注意事項
- 盘点 6 月 yyds 的开源项目!
- Remove HTML tags from Oracle
- Daily English articles, reading accumulation
- Is it safe and reliable for qiniu school to help open a securities account? How to drive
- 最大路径和问题(摘樱桃问题)
- Cross domain problem of canvas drawing caused by background image cache
- Accessories and working process of machine vision system
- Reprint: VTK notes - clipping and segmentation - irregular closed loop clipping -vtkselectpolydata class (black mountain old demon)
猜你喜欢

Redis是什么

滑环的基本结构及工作原理分析

PR 2021 quick start tutorial, how to use audio editing in PR?
![[communication] wide band source DOA estimation method based on incoherent signal subspace (ISM)](/img/5d/bee9a6e50384a7e05e9a71e9fbed9a.jpg)
[communication] wide band source DOA estimation method based on incoherent signal subspace (ISM)

EasyCVR服务private.pem文件被清空,导致无法正常启动该如何处理?

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

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

674. longest continuous increasing sequence

Breadth first search to catch cattle

流媒体集群应用与配置:如何在一台服务器部署多个EasyCVR?
随机推荐
个人买同业存单基金选择什么证券公司开户好,更安全
Haskell configuring vs code development environment (june2022)
Comics | goodbye, postman! One stop collaboration makes apipost more fragrant!
Depth first search to realize the problem of catching cattle
Is the fund reliable and safe
同期群分析是什么?教你用 SQL 来搞定
【leetcode】153. Find the lowest value in the rotation sort array
请问基金是否靠谱,安全吗
利用verilogA模块采样
[image registration] improved SAR image registration based on sar-sift with matlab code
[image registration] SAR image registration based on particle swarm optimization Improved SIFT with matlab code
旋转接头安装使用注意事项
最新Justnews主题源码6.0.1开心版+社交问答插件2.3.1+附教程
机器视觉系统的配件及工作过程
浏览器缓存库设计总结(localStorage/indexedDB)
深度优先搜索实现抓牛问题
如果你会玩这4个自媒体运营工具,副业收入6000+很轻松
2022_ 2_ 16 the second day of learning C language_ Constant, variable
Daily question 1: remove elements
[SV basics] some usage of queue