简体   繁体   中英

Tkinter doesnt open when I use PIL after trying to move images with the msvcrt module

I am trying to make a game in tkinter, as I can't download pygame. I use PIL to display images and I use msvcrt to move the images using arrow keys. I don't get an error, just the window doesn't pop up. If anyone has an answer that would be nice! If any one can find an answer please tell me!

from tkinter import *

from msvcrt import *

from PIL import Image, ImageTk

lost = False

xpos = 0

ypos = 0



def ShowMe():
    load = Image.open('dog.png')
    render = ImageTk.PhotoImage(load)

    img = Label(image=render)
    img.image = render
    img.place(x=0, y=0)
    return


def ShowEnemy():
    load2 = Image.open('freddygifmenu.gif')
    render2 = ImageTk.PhotoImage(load2)

    img2 = Label(image=render2)
    img2.image = render2
    img2.place(x=800, y=875)
    return

def movekeys():
    while True:
        key = getch()
    if key == 'w':
        ypos =+ 1
    elif key == 'a':
        ypos =- 1
    elif key == 'd':
        xpos =+ 1
    elif key == 'a':
        xpos =- 1
    return

def move():
    img.place(x=xpos, y=ypos)
    return

root = Tk()


def AllFunc():
    ShowMe()
    ShowEnemy()
    movekeys()
    move()
    return

root.title('Chase Game')
AllFunc()
root.geometry("{0}x{1}+0+0".format(root.winfo_screenwidth(), root.winfo_screenheight()))
root.mainloop()

You aren't calling mainloop . You need to change the last line to this:

root.mainloop()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM