在Tkin中修复单选按钮的设计

2024-05-13 08:26:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我想链接我的单选按钮与标题,像合并我的标题与单选按钮。这是我实现的代码:

but1 = Radiobutton(text = "Current",value = 0)
but1.place(x =400,y = 150)
but2 = Radiobutton(text = "Previous",value = 1)
but2.place(x =320,y = 150)
but3 = Radiobutton(text = "Current",value = 2)
but3.place(x =400,y = 260)
but4 = Radiobutton(text = "Previous",value = 3)
but4.place(x =320,y = 260)
the_window.geometry("510x430")

label1 = Label(the_window,text = "Most-Discussed \n TV SHOW", font = 
"Times 10 bold")
label1.place(x = 350,y = 110)

label2 = Label(the_window,text = "Most-Discussed \n TV SHOW", font = 
"Times 10 bold")
label2.place(x = 350,y = 230)

这是实际结果:

Actual

这是预期结果:

Expected


Tags: thetext标题valueplacecurrentwindow按钮
1条回答
网友
1楼 · 发布于 2024-05-13 08:26:16

我不知道你是否知道这个,但是这个小部件叫做^{}。请参见下面的示例。你知道吗

另外,我已将您的几何管理器更改为grid

import tkinter as tk

root = tk.Tk()

f1 = tk.LabelFrame(root, text="Most-Discussed \n TV SHOW", labelanchor="n", font="Verdana 12 bold", bd=4)
f1.grid(row=0, column=0, padx=10, pady=10)

f2 = tk.LabelFrame(root, text="Music Vinyl \n Album Chart", labelanchor="n", font="Verdana 12 bold", bd=4)
f2.grid(row=1, column=0, padx=10, pady=10)

but1 = tk.Radiobutton(f1, text="Current", value = 0)
but1.grid(row=0, column=0)
but2 = tk.Radiobutton(f1, text="Previous" ,value = 1)
but2.grid(row=0, column=1)
but3 = tk.Radiobutton(f2, text="Current", value = 2)
but3.grid(row=0, column=0)
but4 = tk.Radiobutton(f2, text="Previous" ,value = 3)
but4.grid(row=0, column=1)

root.mainloop()

Result

相关问题 更多 >