我試圖讓從圖像在以往任何時候我的鼠標點擊的RGB值回到RGB顏色鼠標的Tkinter
我試圖做這一切只用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是可能的。 – alecxe
您使用的是什麼版本的Python? – atlasologist