如何使滚动条看起来像b

2024-10-01 15:43:36 发布

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

enter image description here 我正在为我的商店编码,但看起来我做不出一个好的滚动条。有人能帮我吗,我搜索过makescrollbar,但他们只使用.pack()。所以看起来我需要再做一个框架,但我不想用它。这是我的密码。你知道吗

from tkinter import *
import tkinter as tk
wd=tk.Tk()
wd.title("Sale manager")
#------------Frame-------------
#f1=Frame(wd)
#f1.pack()
#------------Label--------------
lb0 = Label(wd, text ="The FOAK Store", bg = "red", fg ="Black")
lb0.grid(row =0, column =0)
lb1 = Label(wd, text ="Chon loai giay:")
lb1.grid(row =1, column =0)
lb2 = Label(wd, text ="Ngay:")
lb2.grid(row =2, column =0)
lb3 = Label(wd, text ="Gia ban:")
lb3.grid(row =3, column =0)
lb4 = Label(wd, text ="Gia goc:")
lb4.grid(row =4, column =0)

#------------Entry-----------------
scrollbar = Scrollbar(wd)
scrollbar.grid(row=1, column=2)

listbox = Listbox(wd, height=5, width=30, yscrollcommand=scrollbar)
listbox.grid(row=1, column=1)
#------------Data giày-------------
Giay = [
"Nike Air Max Offwhite",
"Nike Vapor Max Offwhite",
"Nike Jordan 1 Offwhite",
"Yeezy 350 Sesame"
]
#-------------Import list box---------
for i in Giay:
   listbox.insert(END, i)

wd.mainloop()

Tags: textimporttkintercolumnframelabelpacktk
1条回答
网友
1楼 · 发布于 2024-10-01 15:43:36

欢迎使用stackoverflow。你知道吗

正如评论所说

  • a) 使用“粘滞”拉伸滚动条以填充行。你知道吗
  • b) 将listbox的yscroll命令链接到滚动条.set你知道吗
  • c) 将滚动条命令链接到列表框.yview你知道吗

对代码的更改如下所示。它们适合于#Entry和#Data gi。你知道吗

列表中必须有更多的项目,使其足够长,也可以滚动。你知道吗

   #      Entry        -
   scrollbar = Scrollbar(wd)
   scrollbar.grid(row=1, column=2, sticky=tk.N+tk.S) # Scrollbar fills the height of row 1

   listbox = Listbox(wd, height=5, width=30, yscrollcommand=scrollbar.set)
   # yscrollcommand linked to scrollbar.set method, not scrollbar 
   listbox.grid(row=1, column=1)
   scrollbar['command']=listbox.yview # Bind scrollbar command to listbox.yview

   #      Data giày      -

在我的windows机器上,tk和ttk滚动条看起来是一样的。您可能想探索使用ttk滚动条,它可能会改善外观。你知道吗

相关问题 更多 >

    热门问题