Python Tkinter按钮/输入方向

时间:2018-12-03 22:33:04

标签: python canvas tkinter anchor tkinter-entry

我正在尝试设置3个条目/按钮的位置。我知道这需要用锚和边来完成,但是我不太了解它是如何工作的。我试图将它们放在一条直线上,第一条在左边,第二条在中间,第三条在右边。我设法做到这一点,但是他们分3条不同的路线。拜托,有人可以向我解释一下,这是怎么工作的?边和锚点值是否与先前的值相关?

import tkinter
import random
canvas=tkinter.Canvas(width=500,height=500)
canvas.pack()

def symbol(x,y,z,color):
    name=entry1.get()        
    for i in range(1,z+1):
        canvas.create_text(x,y,text='                     '+name,angle=(360/z)*i,fill=color,font='Arial 19')

def draw(coordinates):
    x=coordinates.x
    y=coordinates.y
    z=int(entry2.get())
    color=entry3.get()
    symbol(x,y,z,color)


canvas.bind('<Button-1>',draw)

entry1=tkinter.Entry(bg='red')
entry1.pack(side=tkinter.BOTTOM,anchor=tkinter.W)

entry2=tkinter.Entry(bg='green')
entry2.pack(side=tkinter.BOTTOM,anchor=tkinter.CENTER)

entry3=tkinter.Entry(bg='blue')
entry3.pack(side=tkinter.RIGHT,anchor=tkinter.S)

1 个答案:

答案 0 :(得分:0)

import tkinter
import random
canvas=tkinter.Canvas(width=500,height=500)
canvas.pack()

def symbol(x,y,z,color):
    name=entry1.get()        
    for i in range(1,z+1):
        canvas.create_text(x,y,text='                     '+name,angle=(360/z)*i,fill=color,font='Arial 19')

def draw(coordinates):
    x=coordinates.x
    y=coordinates.y
    z=int(entry2.get())
    color=entry3.get()
    symbol(x,y,z,color)


canvas.bind('<Button-1>',draw)

entry1=tkinter.Entry(bg='red')
entry1.place(x=0,y=485)

entry2=tkinter.Entry(bg='green')
entry2.place(x=181,y=485)

entry3=tkinter.Entry(bg='blue')
entry3.place(x=360,y=485)