如何在tkinter中绘制对角线箭头?

时间:2018-02-19 20:58:32

标签: python tkinter tkinter-canvas

我需要从指向黄色框的蓝色和绿色框中绘制两个箭头。我尝试使用create_line绘制对角线,但它没有工作。任何人都可以建议任何我可以绘制这些箭头的方法。 使用create_line时的错误消息是:AttributeError:' _tkinter.tkapp'对象没有属性' create_line'

from tkinter import *
import tkinter as tk


window = Tk()
window.geometry("900x500")
window.configure(background='red')
window.title("Theoretical")

label1 = Label(window, text="Hess' cycle of combustion", fg="black", bg="red", font=("Comic Sans MS", 20))
label1.pack()    

text1 = Text(window, width=20, height = 1, bg= "blue")
text1.place(x=200, y=100)

window.create_line(0, 0, 200, 100)
window.create_line(0, 100, 200, 0, fill="white")

text2 = Text(window, width=20, height = 1, bg= "green")
text2.place(x=520, y=100)

text3 = Text(window, width=20, height = 1, bg= "yellow")
text3.place(x=370, y=250)

##    arrow = Label(window, width=13,height = 1, text = "-------------->", bg= "lawn green", font=("Helvetica", 20))
##    arrow.place(x= 330, y=90)

global textbox
textbox = Text(window, width=400, height=10)
textbox.place(x=0, y= 365)

1 个答案:

答案 0 :(得分:2)

tkinter行有一个package main import ( "html/template" "os" ) func main() { t, err := template.New("").Parse(` <p>{{ .Country }}</p> <p>Want </p> `) if err != nil { panic(err) } err = t.Execute(os.Stdout, map[string]interface{}{ "Country": "US", }) if err != nil { panic(err) } } 选项;但是,正如在评论中指出的那样,arrow是一种create_line方法:因此,您必须使用Canvas对象绘制线条:

这个最小的例子向您展示了如何:

tk.Canvas

enter image description here

请注意,为了避免“难以修复”问题和意外行为,通常建议不要在主命名空间中导入模块(i / e不要import tkinter as tk window = tk.Tk() canvas = tk.Canvas(window) canvas.pack() canvas.create_line(0, 0, 200, 100, arrow=tk.LAST) window.mainloop() ),也不要混合几何管理器( (i / e不要在同一个应用中使用from tkinter import *.place

编辑:

要将小部件放在画布上,您必须use the Canvas.create_window() method

.pack

enter image description here

相关问题