Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.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_Methods_Grid - Fatal编程技术网

网格法是';在python中,一个时钟也不能工作

网格法是';在python中,一个时钟也不能工作,python,tkinter,methods,grid,Python,Tkinter,Methods,Grid,我尝试过各种来源,谷歌搜索等,但我不知道为什么我不能使用grid将这个时钟放到右下角。我试过使用网格、粘性等 from tkinter import * import time def tick(): time_string = time.strftime("%H:%M:%S") clock.config(text=time_string) clock.after(200, tick) root = Tk() root.geometry('500x450') cl

我尝试过各种来源,谷歌搜索等,但我不知道为什么我不能使用grid将这个时钟放到右下角。我试过使用网格、粘性等

from tkinter import *
import time


def tick():
    time_string = time.strftime("%H:%M:%S")
    clock.config(text=time_string)
    clock.after(200, tick)


root = Tk()
root.geometry('500x450')
clock = Label(root, font=("times", 25, "bold"), bg="white")
clock.grid(row=2, column=4)
tick()

mainloop()

对于您的案例,您可以添加:

root.rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)

但是,由于您的示例中只有一个小部件,如果您在窗口中添加更多小部件,上述建议可能不起作用。

import*
通常被认为是不好的做法。好吧,但这并没有导致问题,对吗?我是Python新手。不,这里不应该有错。哦,好吧……谢谢你的回答!