简体   繁体   English

Tkinter 显示超出屏幕

[英]Tkinter display goes outside of the screen

When creating A Gui with Tkinter using lots of images cause the window to be larger than the screen how do I stop this?使用大量图像使用 Tkinter 创建 Gui 时导致窗口大于屏幕,我该如何停止? when running the code the tkinter window displays like this:运行代码时,tkinter 窗口显示如下:

screen shot of tkinter window that is displayed显示的 tkinter 窗口的屏幕截图

    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)

You should either crop the image using a photo editor so that the image is small enough to fit inside the window or run this code in python to make the tkinter window bigger:您应该使用照片编辑器裁剪图像,使图像足够小以适合窗口,或者在 python 中运行此代码以使 tkinter 窗口更大:

self.master.geometry("1000x1000")

inside里面

__init__

and the

"1000x1000"

is x pixels by y pixels.是 x 像素乘 y 像素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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