Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/365.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 * from tkinter import ttk import time root = Tk() root.state("zoomed") #to make it full screen root.title("Vehicle Window Fitt

基本上,我想在屏幕的一侧放置一个时钟,在另一侧放置文本,我使用帧。我怎样才能做到这一点。下面是它现在的样子:

我想让时钟与同一行上的文本对齐,但分开标签。请看一下我的代码,看看你是否能在某些方面帮助我

from tkinter import *
from tkinter import ttk
import time

root = Tk()
root.state("zoomed")  #to make it full screen

root.title("Vehicle Window Fitting - Management System")
root.configure(bg="grey80")

Title = Frame(root, width=675, height=50, bd=4, relief="ridge")
Title.pack(side=TOP, anchor='w')
titleLabel = Label(Title, font=('arial', 12, 'bold'), text="Vehicle Window Fitting - Management System", bd=5, anchor='w')
titleLabel.grid(row=0, column=0)

clockFrame = Frame(root, width=675, height=50, bd=4, relief="ridge")
clockFrame.pack(side=TOP, anchor='e')
clockLabel = Label(clockFrame, font=('arial', 12, 'bold'), bd=5, anchor='e')
clockLabel.grid(row=0, column=1)
curtime = ""

def tick():
    global curtime
    newtime = time.strftime('%H:%M:%S')
    if newtime != curtime:
        curtime = newtime
        clockLabel.config(text=curtime)
    clockLabel.after(200, tick)
tick()

Bottom = Frame(root, width=1350, height=50, bd=4, relief="ridge")
Bottom.pack(side=TOP)


root.mainloop()
使用
网格(行=x,列=y)
。它使相邻对象的放置更加容易。 此外,考虑只使用一个框架的东西。 实际上,您也不需要指定宽度(除非使用
pack/grid\u propagate(0)


您也不需要多个框架,每个标签只需要一个框架。这真的是个坏主意,而且它还需要更多的时间和打字。

我会为标题创建一个框架,并使用类似于
header.pack(side=“top”,fill=“x”)
的东西。然后,我会把两个标签放在那个框架里,一个在左边,一个在右边


然后,我将添加第二个框架来填充GUI的其余部分,所有其他小部件都将放在该空间中

一个问题是试图将
pack
grid
布局管理器混合使用,因为它们不能很好地协同工作。下面是一些只使用
pack
的东西。(注意,您可以在一个帧中使用其中一个,但不能同时使用两个。)

为了在同一“行”上获取这两个项目,添加了另一个名为
topFrame
Frame
,并在其中嵌套了
titleLabel
clockFrame
小部件。此分组允许它们在移动或定位时作为一个单独的单元进行操作-自动影响它们,但保留它们彼此之间的相对位置(

我还删除了
curtime
全局变量,因为它不是必需的(正如您可以通过修改的
tick()
函数看到的那样)

以下是跑步的感觉:


太好了,真不敢相信我没看到。把一个框架放在一个框架里面,而不是放在根里面,太棒了。谢谢你的帮助。@Sam:很高兴听到你的帮助。注意:我刚刚将
底部
框架
粘贴在
的底部(使用
侧=底部
选项)。我不确定那是你想要的还是直接放在新的
顶框下。应该很容易改变。。。
frame_1 = Frame(root, width=675, height=50)
frame_1.pack(side=TOP)

title_lbl = Label(frame_1, text="Lol whateva", height=50, bd=4, font=('arial', 12, 'bold'), relief="ridge", anchor=wherever_you_need_this_to_be)
title_lbl.grid(row=n, column=n)

clock_lbl = Label(clockFrame, font=('arial', 12, 'bold'), bd=5, anchor=wherever_you_need_this_to_be)
clock_lbl.grid(row=n, column=n)
from tkinter import *
from tkinter import ttk
import time

root = Tk()
root.state("zoomed")  #to make it full screen

root.title("Vehicle Window Fitting - Management System")
root.configure(bg="grey80")

topFrame = Frame(root, width=1350, height=50)  # Added "container" Frame.
topFrame.pack(side=TOP, fill=X, expand=1, anchor=N)

titleLabel = Label(topFrame, font=('arial', 12, 'bold'),
                   text="Vehicle Window Fitting - Management System",
                   bd=5, anchor=W)
titleLabel.pack(side=LEFT)

clockFrame = Frame(topFrame, width=100, height=50, bd=4, relief="ridge")
clockFrame.pack(side=RIGHT)
clockLabel = Label(clockFrame, font=('arial', 12, 'bold'), bd=5, anchor=E)
clockLabel.pack()

Bottom = Frame(root, width=1350, height=50, bd=4, relief="ridge")
Bottom.pack(side=BOTTOM, fill=X, expand=1, anchor=S)

def tick(curtime=''):  #acts as a clock, changing the label when the time goes up
    newtime = time.strftime('%H:%M:%S')
    if newtime != curtime:
        curtime = newtime
        clockLabel.config(text=curtime)
    clockLabel.after(200, tick, curtime)

tick()  #start clock
root.mainloop()