嗨我想使用地方将滚动条附加到列表框,但它不会显示在程序中 我的代码:
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()