滚动条未显示-Tkinter

时间:2019-03-11 19:45:36

标签: python-3.x tkinter

我已经在网站上阅读了一些线程来尝试解决此问题,但是没有发现我没有尝试过仍然无法解决的问题。

我很难让滚动条显示给我的小部件。我有2个滚动条,它们在另一个窗口中以相同的方式为列表框和文本小部件编写,并且显示并正常运行,但是在此窗口中,将不会显示2个滚动条。 我的代码与另一个窗口中其他起作用的滚动条的代码相同,但是由于某些原因,这两个未显示。

将它们放置在单个位置上 一些建议将不胜感激。

代码:

import os
import tkinter
from tkinter import *
window_3 = tkinter.Toplevel()
window_3.title('Recipes')
window_3.wm_iconbitmap('recipe.ico')
w = 1024
h = 612
ws = window_3.winfo_screenwidth()
hs = window_3.winfo_screenheight()
x = (ws/2) - (w/2)
y = (hs/2) - (h/2)
window_3.geometry('%dx%d+%d+%d' % (w, h, x, y))
window_3.title('Recipes')
Recipe_Selection = StringVar()
Dish_Type = StringVar()
Recipe = StringVar()
Cook_Time = StringVar()
Serves = StringVar()
ingred = StringVar()
instruct = StringVar()
dish_type = tkinter.Label(window_3, font=('Times 9 bold'), text='Category:', bg = "#FFD599", fg = '#9A0615')
dish_type.pack()
dish_type.place(x=210, y=125)
dish_type_entry = tkinter.Entry(window_3, textvariable=Dish_Type, width = 29, bg = "#FFD599", fg = '#9A0615', justify=CENTER)
dish_type_entry.place(x=275, y=126) recipe = tkinter.Label(window_3, font=('Times 9 bold'), text='Recipe:', bg = "#FFD599", fg = '#9A0615')
recipe.pack()
recipe.place(x=210, y=145)
recipe_entry = tkinter.Entry(window_3, textvariable=Recipe, width = 29, bg = "#FFD599", fg = '#9A0615', justify=CENTER)
recipe_entry.place(x=275, y=146)
serves = tkinter.Label(window_3, font=('Times 9 bold'), text='Serves:', bg = "#FFD599", fg = '#9A0615')
serves.pack()
serves.place(x=547, y=125)
serves_entry = tkinter.Entry(window_3, textvariable=Serves, width = 3, bg = "#FFD599", fg = '#9A0615', justify=CENTER)
serves_entry.place(x=623, y=126)
cook_time = tkinter.Label(window_3, font=('Times 9 bold'), text='Cook Time:', bg = "#FFD599", fg = '#9A0615')
cook_time.pack()
cook_time.place(x=547, y=145)
cook_time_entry = tkinter.Entry(window_3, textvariable=Cook_Time, width = 11, bg = "#FFD599", fg = '#9A0615', justify=CENTER)
cook_time_entry.place(x=623, y=146)
ingred = tkinter.Text(window_3, font=('Times 9'), height = 20, width=40, bd=1, bg = "#FFD599", fg = '#9A0615')
ingred.pack()
ingred.place(x=210, y=200)
yscroll = tkinter.Scrollbar(command=ingred.yview, orient=tkinter.VERTICAL)
yscroll.place(x=452, y=200)
ingred.configure(yscrollcommand=yscroll.set)
instruct = tkinter.Text(window_3, font=('Times 9'), height = 20, width=40, bd=1, bg = "#FFD599", fg = '#9A0615')
instruct.pack()
instruct.place(x=547, y=200)
yscroll = tkinter.Scrollbar(command=instruct.yview, orient=tkinter.VERTICAL)
yscroll.place(x=789, y=200)
instruct.configure(yscrollcommand=yscroll.set)
dish_type_entry.focus()
saveButton = tkinter.Button(window_3, text='Save Recipe', font='Times 9 bold italic', border = 1, height = 1, width = 14, bg = "#F9F8D6", fg = '#9A0615')##, command = Save)
saveButton.pack
saveButton.place(x=293, y=527)
clear1Button = tkinter.Button(window_3, text='Clear Page', font='Times 9 bold italic', border = 1, height = 1, width = 14, bg = "#F9F8D6", fg = '#9A0615')##, command = clear2)
clear1Button.pack
clear1Button.place(x=630, y=527)
backButton = tkinter.Button(window_3, text='Back', font='Times 9 bold italic', border = 1, height = 1, width = 14, bg = "#F9F8D6", fg = '#9A0615')##, command = close3)
backButton.pack
backButton.place(x=449, y=527)

window_3.mainloop()

1 个答案:

答案 0 :(得分:1)

您忘了告诉Scrollbar()它的母版,因此它自然会假定它是根窗口。做:

yscroll = Scrollbar(window_3, ... etc.

顺便说一下,ingredinstruct都与同一个滚动条关联:yscroll,但我只是从剪切和粘贴代码中收集它。另外,您定义StringVar()实例的名称与文本小部件的名称相同。