在Tkinter中设置帧大小和位置 [英] Setting a Frame Size and Location in Tkinter

查看:147
本文介绍了在Tkinter中设置帧大小和位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Tkinter中设置框架大小和框架(主窗口小部件)的位置.基于此答案,我添加了这到我的代码:

I am trying to set a frame-size and the location of the frame (master widget) in Tkinter. Based off of this answer, I added this to my code:

from Tkinter import *
import ctypes
user = ctypes.windll.user32
screensize = (user.GetSystemMetrics(0), user.GetSystemMetrics(1), user.GetSystemMetrics(2), user.GetSystemMetrics(3))

class GetWord:
    def __init__(self, master):
        master.geometry("%s+%s+%s+%s" % (screensize[0], screensize[1], screensize[2], screensize[3]))
        # I added the above in, but not sure how it works
        self.frame = Frame(master, width = screensize[0], height = screensize[1])
        self.frame.grid()

但是,在执行此操作时,我得到一个TclError:

However, when doing this I get a TclError:

Traceback (most recent call last):
  File #file path, line 39, in <module>
    f = GetWord(root)
  File #file path, line 8, in __init__
    master.geometry("%s+%s+%s+%s" % (screensize[0], screensize[1], screensize[2], screensize[3]))
  File "C:\Python2.7.3\lib\lib-tk\Tkinter.py", line 1534, in wm_geometry
    return self.tk.call('wm', 'geometry', self._w, newGeometry)
TclError: bad geometry specifier "1366+768+17+17"

我这样叫课:

root = Tk(className='derp')
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)
f = GetWord(root)
root.mainloop()

我该如何解决?我希望帧从屏幕的中心开始,并以特定的窗口大小开始(现在它是全屏的,但是稍后我将对其进行更改).谢谢!

How can I fix this? I want to have the frame start off in the center of the screen and start at a specific window size (right now it's full-screen but I will change that later on). Thanks!

推荐答案

您需要使用字母"x"代替"+"

You Need to use the letter "x" instead of "+"

master.geometry("%sx%sx%sx%s" % (screensize[0], screensize[1], screensize[2], screensize[3]))

这篇关于在Tkinter中设置帧大小和位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆