2017-11-17 32 views
2

이 코드를 사용하면 전체 화면 모드로 이미지를 표시 할 수 있습니다.주요 개체 (tkinter 및 PIL)에 전체 화면을 표시하는 Python 코드

from tkinter import * 
from PIL import Image, ImageTk 


def showPIL(pilImage): 
    root = Tk() 
    w, h = root.winfo_screenwidth(), root.winfo_screenheight() 
    root.overrideredirect(1) 
    root.geometry("%dx%d+0+0" % (w, h)) 
    root.focus_set() 
    root.bind("<Escape>", lambda e: (e.widget.withdraw(), e.widget.destroy())) 
    canvas = Canvas(root, width=w, height=h) 
    canvas.pack() 
    canvas.configure(background='black') 
    imgWidth, imgHeight = pilImage.size 
    if imgWidth > w or imgHeight > h: 
     ratio = min(w/imgWidth, h/imgHeight) 
     imgWidth = int(imgWidth * ratio) 
     imgHeight = int(imgHeight * ratio) 
     pilImage = pilImage.resize((imgWidth, imgHeight), Image.ANTIALIAS) 
    image = ImageTk.PhotoImage(pilImage) 
    imagesprite = canvas.create_image(w/2, h/2, image=image) 
    root.mainloop() 


img1 = Image.open("img1.png") 
img2 = Image.open('img2.png') 

while True: 
    n = int(input('Numero: ')) 
    if n == 1: 
     showPIL(img1) 
     continue 
    elif n == 2: 
     showPIL(img2) 
     continue 
    else: 
     break 

하지만 때로는 일부 열려있는 창 또는 프로그램 뒤에, 문제가 ... 가 열립니다 이미지가 화면에 주요 대상으로 오지 않는이 ... 어떻게 메인으로 떠나지 않는다 화면?

+1

'e.widget.quit()'을 버튼의 e.widget.destroy()로 변경하면 메인 루프 만 종료됩니다. –

+0

thaaanks! @StevoMitric –

+0

이미지를 화면의 우선 순위로 사용하여이 창을 열려면 어떻게해야합니까? 때로는 다른 프로그램 뒤에 열립니다. @StevoMitric –

답변

0

root.bind 아래에이 root.attributes ("- topmost", True)를 넣을 수 있습니다. @StevoMitric

내 질문을 해결했습니다.