如何解决Tkinter 画布十六进制代码颜色不一致?
我正在做一个项目,我想运行一个 Python 脚本来生成一个带有许多抽象彩色线条的图像,然后将该图像输入到朋友的程序中。也就是说,我用我朋友的程序可以识别和操作的某些十六进制代码对这些行进行了着色,但是即使我指定了这些值,生成的图像也没有我需要的特定颜色。对此,我意识到我使用的 graphics engine 是建立在一个叫做 tkinter 的小东西之上的,不知何故,它正在增加颜色。以下是一些预期和记录的颜色示例:
- 预期>>记录
- 255 128 0 >> 255 126 44
- 0 128 255 >> 0 130 247
- 128 255 0 >> 111 254 80
...等等。另外,如果有帮助,这是我的代码:
from graphics import *
from random import randint
def main():
# First I'll initialize a black window:
win = GraphWin("Click on the screen while the small window is green",1000,700)
win.setBackground("black")
# Indicator window initialization
indicator = GraphWin("green = ready,red = drawing",50,50)
indicator.setBackground("green")
# Setup initial ghost lines
left = Line(Point(10,10),Point(10,690))
right = Line(Point(990,Point(990,690))
lines =[left,right] # this array is really important
arr = []
for x in range(50):
p = win.getMouse() # click
indicator.setBackground("red") # drawing time!
# Gets the midpoint of each line drawn before the click,and
# draws a line from each midpoint to the click.
num = len(lines)
for i in range(num):
q = lines[i].getCenter()
newline = Line(p,q)
doodle(newline,randcolor(),win)
lines.append(newline)
indicator.setBackground("green") # click time!
def randcolor():
r = randint(0,5)
bright_orange = color_rgb(255,128,0) # 255 128-6 0-44
bright_sapphire = color_rgb(0,255) # 0 128-30 255-47
bright_lime = color_rgb(128,255,0) # 128-11 255-4 0-80
dark_orange = color_rgb(128,64,0) # 128-30 64-3 0-16
dark_sapphire = color_rgb(0,128) # 0 64-5 128-4
dark_lime = color_rgb(64,0) # 64-55 128 0-35
# reso_wires = ["#ff8000","#0080ff","#80ff00","#804000","#004080","#408000"]
reso_wires = [bright_orange,bright_sapphire,bright_lime,dark_orange,dark_sapphire,dark_lime]
color = reso_wires[r]
return color
def doodle(x,color,win):
'''
This is your one-stop drawing function. It colors the line,sends it to the
window,and it even supports line declaration as the first parameter.
'''
x.setoutline(color)
x.setWidth(5)
x.draw(win)
nodepoints = [x.getP1(),x.getP2()]
rc = Image(nodepoints[0],"xor_node.png")
rc.draw(win)
rd = Image(nodepoints[1],"xor_node.png")
rd.draw(win)
main()
有人可以帮我调试这个十六进制颜色不一致的问题吗?我完全理解解决这个问题的唯一方法是深入研究 tkinter 的 Canvas 本身的代码并处理 x11 原语。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。