我发现这个代码位于其他地方并稍微编辑以满足我的需要,这意味着以我可以滚动的方式将tkinter标签输出到画布上,但是它不会将标签输出到画布上。代码的目的是为我构建的语音控制程序提供GUI,并将查询和响应输出到画布上。我使用tkinter是合情合理的。这是使用python 3.6.2
vscrollbar = Scrollbar(Window, orient=VERTICAL)
vscrollbar.place(x = 1860, y = 210, height = 850, width = 50)
canvas = Canvas(Window, bd=0, highlightthickness=0,yscrollcommand=vscrollbar.set)
canvas.place(x = 10, y = 210, height = 850, width = 1850)
vscrollbar.config(command=canvas.yview)
# reset the view
canvas.xview_moveto(0)
canvas.yview_moveto(0)
# create a frame inside the canvas which will be scrolled with it
interior = Frame(canvas)
interior_id = canvas.create_window(0, 0, window=interior,anchor=NW)
file = open('querys.txt').read().split('\n')
num = 10
print(len(file))
for i in range(len(file)):
Button(interior, text = file[i]).place()
print(file[i])
file2 = list(file[i])
if file2[0] == '0':
file2.pop(0)
file2.pop(0)
file2[0] = file2[0].upper()
label = Label(interior_id, text = ''.join(file2), bg = 'blue', wraplength = 1000).place(width = 1000, x = 900, y = num)
num+label.winfo_height()
elif file2[0] == '1':
file2.pop(0)
file2.pop(0)
file2[0] = file2[0].upper()
label = Label(interior_id, text = ''.join(file2), bg = 'blue', wraplength = 1000).place(width = 1000, x = 900, y = num)
num+label.winfo_height()
答案 0 :(得分:0)
canvas.CreateText()
如果要设置字体颜色,请使用 fill=" color"