我想寫一個打印出時間表的tkinter程序。要做到這一點,我必須編輯一個文本小部件將答案放在屏幕上。所有的款項相鄰,沒有空格,當我在它們之間增加一個空格時,在我的空白處出現了大括號。我如何擺脫那些花括號?如何在使用tkinter在python中使用空格時擺脫花括號?
P.S.這裏是我的代碼:
#############
# Times Tables
#############
# Imported Libraries
from tkinter import *
# Functions
def function():
whichtable = int(tableentry.get())
howfar = int(howfarentry.get())
a = 1
answer.delete("1.0",END)
while a <= howfar:
text = (whichtable, "x", howfar, "=", howfar*whichtable, ", ")
answer.insert("1.0", text)
howfar = howfar - 1
# Window
root = Tk()
# Title Label
title = Label (root, text="Welcome to TimesTables.py", font="Ubuntu")
title.pack()
# Which Table Label
tablelabel = Label (root, text="Which Times Table would you like to use?")
tablelabel.pack (anchor="w")
# Which Table Entry
tableentry = Entry (root, textvariable=StringVar)
tableentry.pack()
# How Far Label
howfarlabel = Label (root, text="How far would you like to go in that times table?")
howfarlabel.pack (anchor="w")
# How Far Entry
howfarentry = Entry (root, textvariable=StringVar)
howfarentry.pack()
# Go Button
go = Button (root, text="Go", bg="green", width="40", command=function)
go.pack()
# Answer Text
answer = Text (root, bg="cyan", height="3", width="32", font="Ubuntu")
answer.pack()
# Loop
root.mainloop()
感謝您的回答! – 111111100101110111110 2013-04-20 13:41:51