tkinter对话框的元素位置

发布于 2025-01-22 17:37:31 字数 1318 浏览 1 评论 0原文

我正在使用输入和Combobox构建自定义TKINTER对话框窗口。我被放置文本并输入框架。目前,我正在手动放置它们。我正在寻找让TKINTER自动执行此操作的方法(也许使用Pack()方法)。并自动配置高级尺寸。

我的代码:

def ask_unit_len():
    values = ['millimeters', 'micrometers', 'nanometers']
    top = Toplevel()
    top.geometry('170x100')
    top.resizable(False, False)
    top.focus_set()
    top.grab_set()
    top.title('Enter length and units')

    label_length = Label(top, text='Length:')
    label_length.place(x=0, y=0)

    units_type = StringVar()
    length = StringVar()

    answer_entry = Entry(top, textvariable=length, width=10)
    answer_entry.place(x=55, y=0)

    label_units = Label(top, text='Units:')
    label_units.place(x=0, y=30)

    combo = Combobox(top, width=10, textvariable=units_type,
                     values=values)
    combo.place(x=50, y=30)

    button = Button(top, text='Enter',
                    command=lambda:
                    mb.showwarning("Warning",
                                   "Enter all parameters correctly")
                    if (units_type.get() == "" or not length.get().isdigit()
                            or int(length.get()) <= 0)
                    else top.destroy())
    button.place(x=65, y=70)
    top.wait_window(top)
    return int(length.get()), units_type.get()

那么,有什么方法可以执行此操作吗?

I am building custom Tkinter dialog window with Entry and Combobox. I am stuck with placing text and enter frames. Currently I am placing them manually. I am looking for the way to let tkinter do it automatically (maybe with pack() method). And also configure TopLevel size automatically.

My code:

def ask_unit_len():
    values = ['millimeters', 'micrometers', 'nanometers']
    top = Toplevel()
    top.geometry('170x100')
    top.resizable(False, False)
    top.focus_set()
    top.grab_set()
    top.title('Enter length and units')

    label_length = Label(top, text='Length:')
    label_length.place(x=0, y=0)

    units_type = StringVar()
    length = StringVar()

    answer_entry = Entry(top, textvariable=length, width=10)
    answer_entry.place(x=55, y=0)

    label_units = Label(top, text='Units:')
    label_units.place(x=0, y=30)

    combo = Combobox(top, width=10, textvariable=units_type,
                     values=values)
    combo.place(x=50, y=30)

    button = Button(top, text='Enter',
                    command=lambda:
                    mb.showwarning("Warning",
                                   "Enter all parameters correctly")
                    if (units_type.get() == "" or not length.get().isdigit()
                            or int(length.get()) <= 0)
                    else top.destroy())
    button.place(x=65, y=70)
    top.wait_window(top)
    return int(length.get()), units_type.get()

So, is there any way to perform this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文