简体   繁体   English

如何在 tkinter 中用 window 扩展输入框?

[英]How to expand entry box with window in tkinter?

I'm just creating simple window using tkinter which have entry box and search button.我只是使用具有输入框和搜索按钮的 tkinter 创建简单的 window 。 What is want is when i maximize window search bar also starch but it is not happening,想要的是当我最大化 window 搜索栏也淀粉但它没有发生时,

here is my code这是我的代码

import tkinter as tk
from tkinter import ttk
root = tk.Tk()
root.geometry("500x500")
root.title("Wikipedia")

class first:
    def labels(self):
        search_frame = ttk.LabelFrame(root)
        search_frame.pack(side = "top",fill = "both")
        
        search_var = tk.StringVar()
        search_bar = tk.Entry(search_frame,width = 40,textvariable = search_var)
        search_bar.grid(row = 0,column = 0)
        
        search_button = ttk.Button(search_frame,text = "Search")
        search_button.grid(row = 1,column = 0)
boot = first()
boot.labels()
root.mainloop()

I'm beginner in tkinter can you help me.我是 tkinter 的初学者,你能帮帮我吗?

import tkinter as tk
from tkinter import ttk

root = tk.Tk()
root.geometry("500x500")
root.title("Wikipedia")


class first:
    def labels(self):
        search_frame = ttk.LabelFrame(root)
        search_frame.pack(side="top", fill="both")


        search_var = tk.StringVar()
        search_bar = tk.Entry(search_frame, width=20, textvariable=search_var)
        search_bar.pack(fill="x")

        search_button = ttk.Button(search_frame, text="Search")
        search_button.pack()


boot = first()
boot.labels()
root.mainloop()

Not sure this is what you're looking for but try it out.不确定这是否是您要查找的内容,但请尝试一下。 Here I have used fill='x' in the .pack() geometry manager to fill the row在这里,我在.pack()几何管理器中使用了fill='x'来填充行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM