使用Tkinter使用大量图像创建A Gui时,导致窗口大于屏幕,如何停止此操作? 运行代码时,tkinter窗口显示如下:
screen shot of tkinter window that is displayed
import time
from tkinter import *
class App:
def __init__(self,master):
#setting frames
self.master=master
speeddisp=Frame(master)
speeddisp.grid(row=1, column=2)
clockdisp=Frame(master)
clockdisp.grid(row=0,column=0)
indicatorhazard=Frame(master)
indicatorhazard.grid(row=0, column=2)
datedisp=Frame(master)
datedisp.grid(row=0, column=3)
lightdisp=Frame(master)
lightdisp.grid(row=1,column=0)
fandisp=Frame(master)
fandisp.grid(row=1,column=0)
tempdisp=Frame(master)
tempdisp.grid(row=3,column=2)
#setting photos in Photoimage class from TK
self.left_indicator_on_img=PhotoImage(file="left on.gif")
self.left_indicator_off_img=PhotoImage(file="left off.gif")
self.right_indicator_on_img=PhotoImage(file="right on.gif")
self.right_indicator_off_img=PhotoImage(file="right off.gif")
self.hazard_off_img=PhotoImage(file="hazard off.gif")
self.hazard_on_img=PhotoImage(file="hazard on.gif")
self.light_on_img=PhotoImage(file="light on.gif")
self.light_off_img=PhotoImage(file="light off.gif")
self.fan_on_img=PhotoImage(file="fanimg on.gif")
self.fan_off_img=PhotoImage(file="fanimg off.gif")
#defining and placing labels
self.speedlbl=Label(speeddisp, text=('00.00MPH'), font=("Helvetica", 110))
self.speedlbl.grid(row=0,column=0)
self.clocklbl=Label(clockdisp, text=(time.gmtime()[3],":",time.gmtime()[4]))
self.clocklbl.grid(row=0,column=0)
self.leftindicator=Label(indicatorhazard,image=self.left_indicator_off_img)
self.leftindicator.grid(row=0,column=0)
self.rightindicator=Label(indicatorhazard,image=self.right_indicator_off_img)
self.rightindicator.grid(row=0,column=1)
self.hazardindicator=Label(indicatorhazard,image=self.hazard_off_img)
self.hazardindicator.grid(row=0,column=2)
self.datedisplay=Label(datedisp, text=(time.gmtime()[2],"/",time.gmtime()[1],"/",time.gmtime()[0]))
self.datedisplay.grid(row=0,column=0)
self.lights=Button(lightdisp, image=self.light_off_img)
self.lights.grid(row=0,column=0)
self.fanimg=Label(fandisp, image=self.fan_off_img)
self.fanimg.grid(row=0, column=0)
self.temptxt=Label(tempdisp,text='00.00c', font=("Helvetica", 50))
self.temptxt.grid(row=0, column=0)
答案 0 :(得分:0)
您应该使用照片编辑器裁剪图像以使图像足够小以适合窗口内部,或者在python中运行以下代码以使tkinter窗口更大:
self.master.geometry("1000x1000")
内部
__init__
和
"1000x1000"
是x像素乘以y像素。