0
私はRasbperry Pi 3をセットアップし、Python 3を使用しています。私はイメージを取ることができますが、画面上でそれらをリフレッシュする必要があります。非常に新しいtkinker。私はいくつかのコードを持っていますが、キャンバスにすばらしいサイズのイメージを配置し、ボタンの1つが押されたときにそれをリフレッシュする方法を知りたいと思います。python 3 tkinter images
#!/usr/bin/python
import tkinter
import RPi.GPIO as GPIO
import picamera
import time
from PIL import Image, ImageTk
def startup():
def callback(a):
if a==4:
thiscolour="yellow"
camera.capture('/home/pi/Desktop/image.jpg')
if a==2:
thiscolour="red"
lbl.configure(text=thiscolour+" has been pressed")
path = "/home/pi/Desktop/image.jpg"
img = Image.open(path)
new_width = 400
new_height = 600
#img = img.resize((new_width, new_height), Image.ANTIALIAS)
img.save('thisimage.jpg')
path="thisimage.jpg"
path="thisimage.jpg"
image = Image.open(path)
photo = ImageTk.PhotoImage(image)
img = ImageTk.PhotoImage(Image.open(path))
panel.configure(image=photo)
panel.pack()
camera = picamera.PiCamera()
path = "/home/pi/Desktop/image.jpg"
img = Image.open(path)
new_width = 400
new_height = 600
img = img.resize((new_width, new_height), Image.ANTIALIAS)
img.save('thisimage.jpg')
path="thisimage.jpg"
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
buttonyellow = 4
buttonred = 2
t=0
GPIO.setup(buttonyellow, GPIO.IN, GPIO.PUD_UP)
GPIO.setup(buttonred, GPIO.IN, GPIO.PUD_UP)
window=tkinter.Tk()
window.title("Photobooth")
window.geometry("1000x800")
lbl=tkinter.Label(window,text="Instructions")
ent=tkinter.Entry(window)
btn=tkinter.Button(window,text="Press here", bg='red')
btn=tkinter.Button(window,text="Click me",bg='red',command=callback)
btn.pack()
lbl.pack()
ent.pack()
btn.pack()
GPIO.add_event_detect(buttonyellow, GPIO.FALLING, callback=callback, bouncetime=100)
GPIO.add_event_detect(buttonred, GPIO.FALLING, callback=callback, bouncetime=100)
path="thisimage.jpg"
image = Image.open(path)
photo = ImageTk.PhotoImage(image)
img = ImageTk.PhotoImage(Image.open(path))
panel = tkinter.Label(window, image = img)
panel.pack(side = "bottom", fill = "both", expand = "yes")
window.mainloop()
startup()
'ボタン(...、コマンド= FUNCTION_NAME)'と 'canvas.create_image(...)' – furas
が良いいくつかのチュートリアル-http見つける://effbot.org/tkinterbook/ – furas
感謝を。私は多くのチュートリアルを見つけましたが、私はこの分野に固執しているようです。 – stixson99