gpt4 book ai didi

python - 在 tkinter 中定位公式

转载 作者:太空宇宙 更新时间:2023-11-04 02:24:46 25 4
gpt4 key购买 nike

我希望能够将这个公式添加到我的 tkinter 窗口中,然后将这整个东西放在窗口的底部中心。在窗口内,我在 .pack() 中也有一个位于其上方的 Canvas 。

我的代码现在看起来像这样

from tkinter import*

root = Tk()
canvas = Canvas(root, width=1200, height=525)
canvas.pack()

text1 = Label(root, text= "P(H|E)=")
text2 = Label(root, text= "SAA + (")
text3 = Label(root, text= "+ [0.34])")
entry1 = Entry(root)
entry2 = Entry(root)
entry3 = Entry(root)

text1.pack()
entry1.pack()
entry2.pack()
text2.pack()
entry3.pack()
text3.pack()

root.mainloop()

enter image description here

最佳答案

您需要将您想要的内容分解成整齐的行和列。然后为每个子单元制作一个框架,并按照您需要的方式将它们组合在一起。

import tkinter as tk

root = tk.Tk()

leftside = tk.Frame(root)
lbl = tk.Label(leftside, text= "P(H|E)=")
lbl.pack(anchor='c')
leftside.pack(side=tk.LEFT)

rightside = tk.Frame(root)

numerator = tk.Frame(rightside)
entry1 = tk.Entry(numerator, width=5)
entry1.pack(side=tk.LEFT)
lbl = tk.Label(numerator, text='+')
lbl.pack(side=tk.LEFT)
entry2 = tk.Entry(numerator, width=5)
entry2.pack(side=tk.LEFT)
numerator.pack()

division_bar = tk.Frame(rightside, bg='black', height=4)
division_bar.pack(fill=tk.X, expand=True)

denominator = tk.Frame(rightside)
text2 = tk.Label(denominator, text= "SAA + (")
text2.pack(side=tk.LEFT)
entry3 = tk.Entry(denominator, width=5)
entry3.pack(side=tk.LEFT)
text3 = tk.Label(denominator, text= "+ [0.34])")
text3.pack(side=tk.LEFT)
denominator.pack()

rightside.pack(side=tk.LEFT)

root.mainloop()

关于python - 在 tkinter 中定位公式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50690426/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com