Ich versuche, ein Bild und eine Zeile auf Leinwand zu drucken, aber Code funktioniert nicht
Posted: 22 Feb 2025, 14:10
Ich versuche, eine Leinwand mit einer Zeile und einem Bild mit dem folgenden Code zu erstellen, aber es zeigt nur eine Leinwand < /p>
Ich habe versucht, dies in Spyder auszuführen, aber es zeigt nur Leinwand
Code: Select all
from tkinter import *
from PIL import Image, ImageTk
# Create an instance of tkinter frame or window
win=Tk()
# Set the size of the tkinter window
win.geometry("700x350")
from numpy import asarray
# load the image
image = Image.open('image1.jpg')
# convert image to numpy array
data = asarray(image)
print(type(data))
# summarize shape
print(data.shape)
# create Pillow image
image2 = Image.fromarray(data)
print(type(image2))
# summarize image details
print(image2.mode)
print(image2.size)
class Start_Screen:
def __init__(self, master):
self.master = master
# Create a canvas widget
canvas=tkCanvas(win, width=500, height=300)
# Add a line in canvas widget
self.canvas.create_line(50,35,500,35, fill="green", width=5)
self.start_img = Image.open("./image1.jpg")
image1 = ImageTk.PhotoImage(image)
# Add the image to the canvas
self.canvas.create_image(50, 45, anchor='nw', image=image1)
self.canvas.create_line(50,135,500,135, fill="green", width=5)
self.canvas.create_line(50,235,500,235, fill="green", width=5)
self.canvas.pack()
self.canvas.pack(expand=YES, fill=BOTH)
# myvar = canvas.create_line(50,35,500,35, fill="green", width=5)
#mytuple = (int myvar)
#myit = iter(mytuple)
win.mainloop()