【发布时间】:2014-03-25 21:54:01
【问题描述】:
我正在尝试从鼠标在图像中单击的位置获取 RGB 值
我试图只用 Tkinter 来完成这一切,以保持代码简单(并且由于某种原因我无法正确安装 PIL),我不知道这是否可能。感谢您的帮助,我很难过。
from serial import *
import Tkinter
class App:
def __init__(self):
# Set up the root window
self.root = Tkinter.Tk()
self.root.title("Color Select")
# Useful in organization of the gui, but not used here
#self.frame = Tkinter.Frame(self.root, width=640, height=256)
#self.frame.bind("<Button-1>", self.click)
#self.frame.pack()
# LABEL allows either text or pictures to be placed
self.image = Tkinter.PhotoImage(file = "hsv.ppm")
self.label = Tkinter.Label(self.root, image = self.image)
self.label.image = self.image #keep a reference see link 1 below
# Setup a mouse event and BIND to label
self.label.bind("<Button-1>", self.click)
self.label.pack()
# Setup Tkniter's main loop
self.root.mainloop()
def click(self, event):
print("Clicked at: ", event.x, event.y)
if __name__ == "__main__":
App()
【问题讨论】:
-
不要认为没有 PIL 是可能的。
-
你用的是什么版本的 Python?