Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.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 无论发生什么情况,按钮都会占据整个屏幕_Python_Tkinter - Fatal编程技术网

Python 无论发生什么情况,按钮都会占据整个屏幕

Python 无论发生什么情况,按钮都会占据整个屏幕,python,tkinter,Python,Tkinter,嗨,我正在制作一个tkinter程序,但遇到了这个问题。 我试图使用网格方法来集中在屏幕中间的按钮的负载(按钮的数量将动态变化),但是我不能保持按钮的合理大小,我已经遵循了一个有类似问题的人的建议,但是我不能弄清楚我在做什么不同,因为它还没有解决我的问题。 这是我的代码(它使用了一个目录路径,因此对读者来说不起作用,但也许你可以发现我做错了什么) ef open_win3(): 全球第三窗口 第三个窗口=顶级() 第三个窗口配置(高度=1800,宽度=1800,bg=“chocolate1”)

嗨,我正在制作一个tkinter程序,但遇到了这个问题。 我试图使用网格方法来集中在屏幕中间的按钮的负载(按钮的数量将动态变化),但是我不能保持按钮的合理大小,我已经遵循了一个有类似问题的人的建议,但是我不能弄清楚我在做什么不同,因为它还没有解决我的问题。 这是我的代码(它使用了一个目录路径,因此对读者来说不起作用,但也许你可以发现我做错了什么)

ef open_win3():
全球第三窗口
第三个窗口=顶级()
第三个窗口配置(高度=1800,宽度=1800,bg=“chocolate1”)
创建按钮()
def create_thirdwindow_按钮():
bf=帧(第三个窗口,bg=“蓝色”)
bf.网格(行=0,列=0,sticky=“NESW”)
bf.rowconfigure(0,权重=1)
bf.columnconfigure(0,权重=1)
第三个窗口。网格行配置(0,权重=1)
第三个窗口。网格列配置(0,权重=1)
计数=0
x=1
y=0
mypath=“C:\\Users\\link\\OneDrive\\Desktop\\python stuff\\screenshot example\\Snapshots by category”
对于listdir(mypath)中的g:
计数+=1
对于listdir(mypath)中的I:
btp=mypath+“\\”+str(一)
打印(btp)
屏幕截图\u snap=按钮(bf,text=str(I),width=1,height=1,bg=“chocolate3”,activebackground=“white”,padx=10,pady=10)
屏幕截图\u快照网格(sticky=“NESW”)
屏幕截图\u snap.grid\u rowconfigure(0,权重=1)
屏幕截图\u snap.grid\u columnconfigure(0,权重=1)
x+=10
如果y<计数:
y+=1

非常感谢你的帮助

screenshot\u snap.grid(sticky=“NESW”)
。我想你已经将sticky设置为
NESW
,这将强制小部件展开。@Sujay啊,我明白了,我只是认为它的意思是将其居中。因为那将是东北部的中部。。。。。。但我明白为什么这意味着现在就要扩张了
ef open_win3():
    global third_window
    third_window = Toplevel()
    third_window.config(height = 1800,width = 1800, bg = "chocolate1")
    create_thirdwindow_button()


def create_thirdwindow_button():
    bf = Frame(third_window,bg = "blue")
    bf.grid(row=0, column=0,sticky="NESW")
    bf.rowconfigure(0,weight = 1)
    bf.columnconfigure(0,weight =1)
    third_window.grid_rowconfigure(0, weight=1)
    third_window.grid_columnconfigure(0, weight=1)

    count = 0
    x = 1
    y = 0
    mypath = "C:\\Users\\link\\OneDrive\\Desktop\\python stuff\\screenshot example\\Snapshots by catagory"
    for g in listdir(mypath):
        count += 1

    for I in listdir(mypath):
        btp = mypath +"\\"+str(I)
        print(btp)
        screenshot_snap = Button(bf,text = str(I),width = 1,height = 1, bg =  "chocolate3",activebackground = "white",padx= 10,pady =10)
        screenshot_snap.grid(sticky = "NESW")
        screenshot_snap.grid_rowconfigure(0, weight=1)
        screenshot_snap.grid_columnconfigure(0, weight=1)
        x += 10
        if y < count:
            y += 1