幾周來,我嘗試讓我的應用程序滾動條。但是與TKinter模塊有衝突,我不知道如何解決它。沒有我的模塊,它是滾動條,但不是與他們。你可以幫我請一下這個例子嗎?Python - 滾動條如何處理標籤,單選按鈕,按鈕?
Lovespock
Ps。請好,我是一個半新手。 :/:p PP。我沒有textdefinitions代碼和所有單選按鈕
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()
什麼錯誤(衝突)消息? – frankyjuang
沒有錯誤消息,應用程序不會執行任何操作。她沒有開始,但她沒有滾動條。 – LoveSpock
你能提供完整的代碼嗎? – frankyjuang