我需要一个滚动条在元素下滚动,看到当从第一个窗口创建超过30个元素时,屏幕不会填写正确的模式:
import numpy as np
import matplotlib.pyplot as plt
from Tkinter import *
import tkMessageBox
import tkSimpleDialog
from matplotlib import pylab
prefixo = "vetor"
def makeWidgets():
global entries
window = Tk()
window.title('Vetores')
form = Frame(window)
form.pack()
entries = {}
numero = tkSimpleDialog.askinteger("Vetores", "Digite o numero de vetores a serem usados:")
for ix in range(numero):
label = "%s %s" % (prefixo , ix + 1)
lab = Label(form, text=label)
ent = Entry(form)
lab.grid(row=ix, column=0)
ent.grid(row=ix, column=1)
entries[label] = ent
Button(window, text="Histograma", command=histograma).pack(side=LEFT)
Button(window, text="Media", command=media).pack(side=LEFT)
Button(window, text="Mediana", command=mediana).pack(side=LEFT)
window.mainloop()
def pegavalores():
valores = []
for chave, entrada in sorted(entries.items()):
valores.append(entrada.get())
valores = np.asarray(valores, dtype=np.float64)
return valores
def histograma():
histograma = pegavalores()
pylab.grid(True)
plt.hist(histograma)
plt.show()
def media():
media = pegavalores()
elementos = len(media)
valormedio = np.sum(media)/elementos
tkMessageBox.showinfo("Media", valormedio)
def mediana():
mediana = pegavalores()
resultado = np.median(mediana)
tkMessageBox.showinfo("Mediana", resultado)
window = makeWidgets()
答案 0 :(得分:0)
您必须使用滚动条窗口小部件(http://effbot.org/tkinterbook/scrollbar.htm)。 不幸的是,它不能很好地直接使用帧。当我与Tkinter合作时,我发现这个扩展非常有用:
http://tkinter.unpythonic.net/wiki/VerticalScrolledFrame
如果将其包含在脚本中,则可以轻松地将小部件放在内部框架中以获得垂直滚动条,如:
window.title('Vetores')
form = VerticalScrolledFrame(window)
form.pack(fill=BOTH, expand=1)
entries = {}
numero = tkSimpleDialog.askinteger("Vetores", "Digite o numero de vetores a serem usados:")
for ix in range(numero):
label = "%s %s" % (prefixo , ix + 1)
lab = Label(form.interior, text=label)
ent = Entry(form.interior) ...