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
しかし、私は問題を抱えている...開く 画像は、私がメインとして残すにはどうすればよい...時にはそれがいくつか開いているウィンドウやプログラムの背後にある、画面上の主な目的として付属していません。画面?
'e.widget.quit()'をボタンの 'e.widget.destroy()'に変更して、メインループだけを終了させます。 –
thaaanks! @StevoMitric –
イメージを画面上で優先してこのウィンドウを開くにはどうすればよいですか? @StevoMitric –