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

边栏推荐
- PR 2021 quick start tutorial, how to use audio editing in PR?
- 盘点 6 月 yyds 的开源项目!
- Report on the convenient bee Lantern Festival: the first peak sales of pasta products this year; prefabricated wine dumplings became the winners
- 旋轉接頭安裝使用注意事項
- Daily practice: delete duplicates in the ordered array
- Is it safe to open an account on great wisdom
- Is it safe to open an account on the flush
- [Gym 102423]-Elven Efficiency | 思维
- [eight part essay] MySQL
- 流媒体集群应用与配置:如何在一台服务器部署多个EasyCVR?
猜你喜欢
![[image registration] SAR image registration based on particle swarm optimization Improved SIFT with matlab code](/img/b5/02979b50db885f0606dce455182ac4.jpg)
[image registration] SAR image registration based on particle swarm optimization Improved SIFT with matlab code

Analysis of basic structure and working principle of slip ring

Daily question 1: the number of numbers in the array 2

浏览器缓存库设计总结(localStorage/indexedDB)
![[eight part essay] MySQL](/img/8e/719149fb49f1850baf5bab343955bf.jpg)
[eight part essay] MySQL
![[image denoising] matlab code for removing salt and pepper noise based on fast and effective multistage selective convolution filter](/img/7b/f9cea5dfe6831f5f226b907e2095eb.jpg)
[image denoising] matlab code for removing salt and pepper noise based on fast and effective multistage selective convolution filter
![[Gym 102423]-Elven Efficiency | 思维](/img/cf/b65f3db1580a83478f8351cea22040.png)
[Gym 102423]-Elven Efficiency | 思维

流媒体集群应用与配置:如何在一台服务器部署多个EasyCVR?

Program environment and pretreatment

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
随机推荐
Depth first search to realize the problem of catching cattle
流媒体集群应用与配置:如何在一台服务器部署多个EasyCVR?
Structure of the actual combat battalion | module 5
Résumé de Manon, 25 ans, diplômé en trois ans
Pinhole camera with added lens
What is redis
[image detection] recognition of the front and back of a coin based on texture features with matlab code attached
var、let、const 三者的区别
Mapbox GL loading local publishing DEM data
FSS object storage how to access the Intranet
【leetcode】1719. Number of schemes for reconstructing a tree
Blazor University (34) forms - get form status
【leetcode】153. Find the lowest value in the rotation sort array
[leetcode] 522. Longest special sequence II violence + double pointer
Is it safe to open an account on great wisdom
【leetcode】17. Letter combination of telephone number
[staff] pedal mark (step on pedal ped mark | release pedal * mark | corresponding pedal command in MIDI | continuous control signal | switch control signal)
Leetcode daily question: implementing strstr()
Browser cache library design summary (localstorage/indexeddb)
EasyCVR新建用户后,视频调阅页面不能点击的问题修复