我是Python的初学者,我想将图像添加到使用以下代码制作的小部件中,显示尺寸为1024 * 600 px /全屏,我使用LCD 7 inc。有人在帮助我做到这一点吗?
import time
import serial
from Tkinter import *
serial_speed = 115200
serial_port = '/dev/ttyACM0'
ser = serial.Serial(serial_port, serial_speed, timeout=1)
class Application(Frame):
def measure(self):
ser.write("m")
data = ser.readline()
# If the answer is not empty, process & display data
if (data != ""):
processed_data = data.split(",")
self.tegangan_data.set("TEGANGAN: " + str(processed_data[0]))
self.tegangan.pack()
self.arus_data.set(" ARUS : " + str(processed_data[1]))
self.arus.pack()
self.daya_data.set(" DAYA : " + str(processed_data[2]))
self.daya.pack()
self.torsi_data.set(" TORSI : " + str(processed_data[3]))
self.torsi.pack()
self.panas_data.set(" PANAS MESIN : " + str(processed_data[4]))
self.panas.pack()
self.jarak_data.set(" JARAK TEMPUH : " + str(processed_data[5]))
self.jarak.pack()
# Wait 1 second between each measurement
self.after(500,self.measure)
# Create display elements
def createWidgets(self):
self.tegangan = Label(self, textvariable=self.tegangan_data, font=('Verdana', 20, 'bold'))
self.tegangan_data.set("Tegangan")
self.tegangan.pack()
self.arus = Label(self, textvariable=self.arus_data, font=('Verdana', 20, 'bold'))
self.arus_data.set("Arus")
self.arus.pack()
self.daya = Label(self, textvariable=self.daya_data, font=('Verdana', 20, 'bold'))
self.daya_data.set("Daya")
self.daya.pack()
self.torsi = Label(self, textvariable=self.torsi_data, font=('Verdana', 20, 'bold'))
self.torsi_data.set("Torsi")
self.torsi.pack()
self.panas = Label(self, textvariable=self.panas_data, font=('Verdana', 20, 'bold'))
self.panas_data.set("Panas mesin")
self.panas.pack()
self.jarak = Label(self, textvariable=self.jarak_data, font=('Verdana', 20, 'bold'))
self.jarak_data.set("Daya")
self.jarak.pack()
def __init__(self, master=None):
Frame.__init__(self, master)
self.tegangan_data = StringVar()
self.arus_data = StringVar()
self.daya_data = StringVar()
self.torsi_data = StringVar()
self.panas_data = StringVar()
self.jarak_data = StringVar()
self.createWidgets()
self.pack()
self.measure()
root = Tk()
app = Application(master=root)
app.mainloop()
看起来像这样(在链接中),我想在它的正下方添加一个图像(在整个窗口中)
https://i.stack.imgur.com/c4pVF.jpg