C
C
CripplingDepression2020-05-12 23:04:58
Python
CripplingDepression, 2020-05-12 23:04:58

How to insert an image?

I can not solve the problem of inserting an image in the code:

import random
from PIL import Image, ImageDraw
from tkinter import *

root = Tk()
root.title("Проект Олега")
root.geometry("500x500+700+250")

def new_window1(event):
    window1 = Toplevel(root.deiconify())
    window1.geometry("500x500+700+250")
    image = Image.open(ТаблицаМенделевия.jpeg)
    draw = ImageDraw.Draw(ТаблицаМенделевия.jpeg)
    width = image.size[0]
    height = image.size[1]
    pix = image.load()

def new_window4(event):
    window4 = Toplevel(root.deiconify())
    window4.geometry("500x500+700+250")
    btn4 = Button(window4, text="Начать", bd="7")
    btn4.bind('<Button->', new_window1)
    btn4.pack()
    btn5 = Button(window4, text="Инфо", bd="7")
    btn5.bind('<Button->', new_window2)
    btn5.pack()
    btn5 = Button(window4, text="Выйти", bd="7")
    btn5.bind('<Button->', new_window3)
    btn5.pack()

def new_window2(event):
    window2 = Toplevel(root.deiconify())
    window2.geometry("500x500+700+250")
    btn10 = Button(window2, text="Назад в меню")
    btn10.bind('<Button->', new_window4)
    btn10.pack()

def new_window3(event):
    window3 = Toplevel(root.deiconify())
    window3.geometry("500x500+700+250")
    text1 = "Чтобы выйти из игры, \nзакройте основное (самое первое) окно.\n Спасибо, что сыграли в эту игру!"
    l1=Label(window3, text=text1, justify=CENTER)
    l1.pack()

label1 = Label(root, text="Игра по изучению электронов")
label1.pack()

btn1 = Button(root, text="Начать", bd="7", background="#FF0000", activebackground="#8B0000", activeforeground="#FFFFFF")
btn1.bind('<Button->', new_window1)
btn1.pack()

btn2 = Button(root, text="Инфо", bd="7", background="#008000", activebackground="#006400", activeforeground="#FFFFFF")
btn2.bind('<Button->', new_window2)
btn2.pack()

btn3 = Button(root, text="Выйти", bd="7", background="#0000FF", activebackground="#00008B", activeforeground="#FFFFFF")
btn3.bind('<Button->', new_window3)
btn3.pack()

root.mainloop()

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Karbivnichy, 2020-05-13
@CripplingDepression

A great example of why you shouldn't import everything from a module with an asterisk: Here, using the Image class from tkinter, which doesn't have an open() method. Also, the file name is passed to the open method as a string enclosed in single or double quotes. As a result, you have a mess of classes and methods with the same names, but from different libraries. Demolish the code completely, and rewrite the program from scratch - it will be easier.
from tkinter import *
image = Image.open(ТаблицаМенделевия.jpeg)

Y
yerdnaandrey, 2020-05-12
@yerdnaandrey

you didn't put in image.open() "

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question