Python - Scrollbar如何使用标签,单选按钮,按钮?

时间:2017-05-29 13:28:07

标签: python tkinter scrollbar

几周后,我尝试获取应用程序滚动条。但是与TKinter模块存在冲突,我不知道如何解决它。没有我的模块,它是滚动条但不是它们。你可以用我的申请表中的这些例子来帮助我吗?

Lovespock

聚苯乙烯。请你好,我是一个半新手。 :/:p 聚苯硫醚。我的代码没有textdefinitions和所有radiobuttons

from __future__ import print_function
from Tkinter import *
import Tkinter as tk
from result import *

master = tk.Tk()

frame=Frame(master,width=300,height=300)
frame.pack
canvas=Canvas(frame,bg='#FFFFFF',width=300,height=300,scrollregion=(0,0,500,500))

vbar=Scrollbar(frame,orient=VERTICAL)
vbar.pack(side=RIGHT,fill=Y)
vbar.config(command=canvas.yview)

def sumlist():
    sum = (vallist_a[-1]) + (vallist_b[-1]) + (vallist_c[-1]) + (vallist_d[-1]) + (vallist_e[-1]) + (vallist_f[-1]) + (vallist_g[-1]) + (vallist_h[-1]) + (vallist_i[-1])
    print (sum)

def create_window(): #Definion und Festlegung neues Fenster
    toplevel = Toplevel()
    toplevel.title('result')
    toplevel.geometry('1500x1000')
    toplevel.focus_set()
    sum = (vallist_a[-1]) + (vallist_b[-1]) + (vallist_c[-1]) + (vallist_d[-1]) + (vallist_e[-1]) + (vallist_f[-1]) + (vallist_g[-1]) + (vallist_h[-1]) + (vallist_i[-1])
    if 9<= sum <= 14:
        msg = Message(toplevel, text = result1)
        msg.config(bg='lightgreen', font=('times', 24, 'italic'))
        msg.pack()
    if 15<= sum <= 21:
        msg = Message(toplevel, text = result2)
        msg.config(bg='lightgreen', font=('times', 24, 'italic'))
        msg.pack()
    if 22<= sum <= 28:
        msg = Message(toplevel, text = result3)
        msg.config(bg='lightgreen', font=('times', 24, 'italic'))
        msg.pack()
    if 29<= sum <= 36:
        msg = Message(toplevel, text = result4)
        msg.config(bg='lightgreen', font=('times', 24, 'italic'))
        msg.pack()


def ShowChoice(text, v, testlist):
    print(v.get())
    testlist.append(v.get())

vallist_a = []
vallist_b = []
vallist_c = []
vallist_d = []
vallist_e = []
vallist_f = []
vallist_g = []
vallist_h = []
vallist_i = []


hello = [
    (1),
    (2),
    (3),
    (4),
]

officer = [
    (1),
    (2),
    (3),
    (4),
]

borg = [
    (1),
    (2),
    (3),
    (4),
]

vulcans = [
    (1),
    (2),
    (3),
    (4),
]

home = [
    (1),
    (2),
    (3),
    (4),
]

crew = [
    (1),
    (2),
    (3),
    (4),
]

important = [
    (1),
    (2),
    (3),
    (4),
]

take = [
   (1),
   (2),
   (3),
   (4),
]

bye = [
    (1),
    (2),
    (3),
    (4),
]

tk.Label(canvas, text='Which Captain are you?', font=("Helvetica", 30), fg = 'red').pack()

varhello = tk.IntVar()

for i, val in enumerate(hello):
    tk.Radiobutton(canvas, text=text[i], variable=varhello, value=val,
    command=lambda t=text, a=varhello: ShowChoice(t, a, vallist_a)).pack(anchor=tk.N)


Button(canvas, text='forward', command=create_window).pack(padx=5, anchor=N, pady=4)


canvas.config(width=300,height=300)
canvas.config(yscrollcommand=vbar.set)
canvas.pack(side=LEFT,expand=True,fill=BOTH)

master.mainloop()

1 个答案:

答案 0 :(得分:0)

要在Canvas内滚动小部件,而不是使用通常的packgridplace方法来显示小部件,您需要使用{{1} create_window的方法。该方法的语法是 CanvasHere您可以获得有关关键字参数的详细信息。

示例:

canvas.create_window(x, y, window=widget, **kw)