Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.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标签大小不匹配_Python_Tkinter - Fatal编程技术网

Python Tkinter标签大小不匹配

Python Tkinter标签大小不匹配,python,tkinter,Python,Tkinter,我正在进行人机界面设计。。。 我已经创建了一个标签数组…我对数组中的所有标签使用了相同的标签和属性,但是当我执行代码时,标签的大小彼此不匹配 这是我的代码 from tkinter import * import time root = Tk() class Clock: def __init__(self): self.time1 = '' self.time2 = time.strftime('%H:%M:%S') self

我正在进行人机界面设计。。。 我已经创建了一个标签数组…我对数组中的所有标签使用了相同的标签和属性,但是当我执行代码时,标签的大小彼此不匹配

这是我的代码

from tkinter import *    
import time

root = Tk()

class Clock:
    def __init__(self):
        self.time1 = ''
        self.time2 = time.strftime('%H:%M:%S')
        self.mFrame = Frame()
        self.mFrame.pack(side=TOP,fill=X)

        self.bottomFrame = Frame()
        self.bottomFrame.pack(side=BOTTOM,fill=BOTH)

        root.title('HUMAN MACHINE INTERFACE')

        self.company_name=Label(self.mFrame, text='Host Company Name', font=('Arial',24,'bold','underline'),bg='white',relief=RAISED).pack(fill=X)

        self.machine_name=Label(self.mFrame, text='Machine name', font=('Arial',24,'bold','underline'),bg='yellow',relief=RAISED).pack(fill=X)

        self.my_company_name=Label(self.mFrame, text='SYNERGY AUTOMATION', font=('Arial',24,'bold','underline'),relief=SUNKEN).pack(side=LEFT)

        self.watch = Label(self.mFrame, text=self.time2, font=('times',24,'bold'),relief=SUNKEN)
        self.watch.pack(side=RIGHT)

        self.clock() #first call it manually

        num=['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',]
        r=0
        c=0

        for i in num:
            Label(self.bottomFrame, text=i,bg='red',fg='white',font=(34),padx=50,pady=20,relief=SUNKEN).grid(row=r,column=c)
            c = c + 1
            if c == 4 or c == 8:
                c=0
                r=r+1




    def clock(self): 
        self.time2 = time.strftime('%H:%M:%S')
        self.watch.configure(text=self.time2)
        self.mFrame.after(200, self.clock) #it'll call itself continuously

obj1 = Clock()
root.mainloop()
调用grid时没有使用sticky选项。如果没有它,标签将只足够大以包含文本。如果您想让它们填充表格单元格,请使用sticky=N+S+E+W之类的方法

顺便说一下

self.company_name=Label(...).pack(fill=X)
您正在将self.company\u name设置为None,因为这是pack返回的内容。tkinter的最佳实践是将小部件的创建与在屏幕上的布局分开:

self.company_name=Label(...)
...
self.company_name.pack(fill=X)
self.company_name=Label(...)
...
self.company_name.pack(fill=X)