python - tkinter 如何使用位置将滚动条附加到列表框?
问题描述
嗨,我想使用 place 将滚动条附加到列表框,但它没有出现在我的代码中:
txt = Listbox(root, width = 60, height = 25,bd = 0, relief = SUNKEN)
lb2 = Listbox(root, width = 15, height = 25,bd=0)
txt.place(relx=0.4, rely=0.45, width = 360, height = 400, anchor=CENTER)
lb2.place(relx=0.87, rely=0.45,anchor=CENTER )
scrollbar = Scrollbar(frame, orient="vertical")
scrollbar.config(command=txt.yview)
scrollbar.place(x=400,rely=0.45, width=10, height = 100, anchor = "center")
txt.config(yscrollcommand=scrollbar.set)
如果我运行程序,我看不到滚动条。
编辑:对不起,这是我的完整代码
from tkinter import *
root = Tk()
root.geometry("500x600")
frame = Frame(root)
frame.pack()
#l1 = Label(root, text="Enter Message ")
l2 = Label(root, text="Enter Your Name ",font=("squarefont", 25))
ent = Entry(root, state='disabled',bd=1,borderwidth = 0,highlightthickness=0)
ent1 = Entry(root, borderwidth = 0,highlightthickness=0)
btn = Button(root, text="send",state='disabled',font=(None, 25),borderwidth = 0,highlightthickness=0)
btn1 = Button(root, text="Ok",borderwidth = 0,highlightthickness=0,font=(None, 15))
txt = Listbox(root, width = 60, height = 25,bd = 0, relief = SUNKEN)
lb2 = Listbox(root, width = 15, height = 25,bd=0)
txt.place(relx=0.4, rely=0.45, width = 360, height = 400, anchor=CENTER)
lb2.place(relx=0.87, rely=0.45,anchor=CENTER )
scrollbar = Scrollbar(frame, orient="vertical")
scrollbar.config(command=txt.yview)
scrollbar.place(x=400,rely=0.45, width=10, height = 100, anchor = "center")
txt.config(yscrollcommand=scrollbar.set)
btn.place(relx = 0.87, rely =0.87, width = 90, height = 90, anchor=CENTER)
ent.place(relx=0.4, rely =0.87, width = 360, height = 90, anchor=CENTER)
btn1.place(relx =0.9, rely =0.08, anchor="center")
l2.place(relx =0.6, rely =0.08, anchor="e")
ent1.place(relx =0.6, rely =0.08, height = 30, anchor="w")
ent1.focus_set()
root.title("Messenger")
root.mainloop()
解决方案
推荐阅读
- android - TOCO 无法使用 --allow_custom_ops 转换不受支持的操作
- spring-boot - 令牌始终无效
- kubernetes - 在 minikube 上安装 helm 返回错误
- python - 在其类之外调用类方法是否违反 pep 风格规则?
- environment-variables - 无法在 Nuxt.js 中访问 server/index.js 中的环境变量
- php - 如何避免通过php扫描某些目录
- android - 如何在 Kotlin 中使用日期选择器为 EditText 设置文本
- spring-boot - 使用 ssl 在 AWS 上使用 Spring-boot-starter-data-redis 的启动错误
- jquery - Visual Studio 2019 - 添加客户端库(TypeScript、JQuery 等)的正确方法
- c# - 在 Azure Durable Functions 中,如何正确确定大量并行活动的进程?