Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python tkinter主窗口在.grid()小部件时大小不正确_Python_Python 3.x_Dictionary_Graphics_Tkinter - Fatal编程技术网

Python tkinter主窗口在.grid()小部件时大小不正确

Python tkinter主窗口在.grid()小部件时大小不正确,python,python-3.x,dictionary,graphics,tkinter,Python,Python 3.x,Dictionary,Graphics,Tkinter,我有一个游戏板,它是行x列列表 最小尺寸为2x2,最大尺寸为10x10,行数不相等:列数可以(例如2x3、4x9) 主窗口对象没有预先确定的几何体大小设置,对于创建二维地图的was中的每个列表元素,窗口小部件(按钮)都包含.grid() 理想情况下,给定使用的方法,这将在主窗口内生成一个漂亮的边=到边贴图 不幸的是,测试表明,虽然这对于列数>3的映射是正确的,但当列数时,当列数时,这似乎是平台特有的限制。我不能在我的Mac电脑上复制这个问题,但我可以在windows虚拟机上复制。显然,Windo

我有一个游戏板,它是行x列列表

最小尺寸为2x2,最大尺寸为10x10,行数不相等:列数可以(例如2x3、4x9)

主窗口对象没有预先确定的几何体大小设置,对于创建二维地图的was中的每个列表元素,窗口小部件(按钮)都包含.grid()

理想情况下,给定使用的方法,这将在主窗口内生成一个漂亮的边=到边贴图


不幸的是,测试表明,虽然这对于列数>3的映射是正确的,但当列数时,当列数时,这似乎是平台特有的限制。我不能在我的Mac电脑上复制这个问题,但我可以在windows虚拟机上复制。显然,Windows不允许窗口的宽度小于标题栏上按钮和图标所需的空间


我的建议是给行和列一个正的权重,这样它们将增长到适合窗口的大小,然后使用
粘滞
选项使按钮填充指定给它们的空间。

使用
放置
而不是
网格
有什么原因吗<代码>网格使创建类似网格的布局变得更加容易。该死,我在写这个问题时一定是疯了。。。显然,我使用了
.grid()
方法。不过,谢谢你的回答:1。我100%确定我没有为根2设置Geometry。在Py 3.4.3中,您的代码在我的Win7上仍然存在相同的问题,请参见链接图3。我知道Py样式,但因为我讨厌下划线,所以我坚持使用JS样式:)
def createMap (): #creates rows x columns 2D list - a map
    global rowsEntryVar, columnsEntryVar, mapList
    mapList = []
    for row in range(rowsEntryVar):
        tempList = []
        for column in range(columnsEntryVar):
            tempList.append(Button(root, bd=0, bg=redMagenta, activebackground=redMagenta))
        mapList.append(tempList)
def drawMap ():
    global mapList
    for row in range(len(mapList)):
        for column in range(len(mapList[row])):
            mapList[row][column].grid(row=row, column=column)
from Tkinter import *

def create_map (rowsEntryVar, columnsEntryVar): #creates rows x columns 2D list - a map
    mapList = []
    for row in range(rowsEntryVar):
        tempList = []
        for column in range(columnsEntryVar):
            tempList.append(Button(root, text="%s-%s" % (row, column),
                            bd=0, bg="magenta2", activebackground=r"magenta3"))
        mapList.append(tempList)
    return mapList

def draw_map(mapList):
    for row in range(len(mapList)):
        for column in range(len(mapList[row])):
            mapList[row][column].grid(row=row, column=column)


root = Tk()
map_list=create_map(4, 3)
draw_map(map_list)
root.mainloop()