python标签不实时更新

时间:2018-11-28 20:12:52

标签: python python-3.x matplotlib tkinter

我解决了具有相同问题的问题,而解决方案主要是在.set ()中。

我是新手,我做了同样的事,但没有成功。请帮助理解并指出错误。

我这样做是为了使dp1o中的值根据公式xmax进行更改,但似乎仅对自动分配的零进行计算。

from math import *
from tkinter import *

root = Tk()
f_top = Frame(root)
root.title('Полет ядра')
g = 9.81
dx = 0.01
v = IntVar()
an = IntVar()
t = IntVar()
vx = IntVar()

def analysis():
    v = int(entry1.get())
    an = int(entry2.get())


    t = (((2 * v * sin(an)) / g))
    vx = v * cos(an)

    xmax = vx * t * cos(an)

    dp1o.config(text=xmax)


first = LabelFrame(root, text='Данные для первого графика')
first.pack(side='left')

second = Label(first, text='Начальная скорость')
second.pack()

entry1 = Entry(first, width=10, textvariable=v)
entry1.pack()

third = Label(first, text='Угол выстрела')
third.pack()

entry2 = Entry(first, width=10, textvariable=an)
entry2.pack()


first = LabelFrame(root, text='Расчет')
first.pack(side='right')
dp1 = Label(first, text='Дальность полета 1 тела')
dp1.pack()
dp1o = Label(first, text='')
dp1o.pack()


button = Button(root, text="Сгенерировать", command=analysis())
button.pack(side='left')

root.mainloop()

1 个答案:

答案 0 :(得分:0)

您的问题是您在()之后通过了analysis。处理命令时,无需在要调用的函数后放置()。

这是您代码的有效版本。

from math import *
from tkinter import *

root = Tk()
f_top = Frame(root)
root.title('Полет ядра')
g = 9.81
dx = 0.01
v = IntVar()
an = IntVar()
t = IntVar()
vx = IntVar()

def analysis():
    v = int(entry1.get())
    an = int(entry2.get())


    t = (((2 * v * sin(an)) / g))
    vx = v * cos(an)

    xmax = vx * t * cos(an)

    dp1o.config(text=xmax)


first = LabelFrame(root, text='Данные для первого графика')
first.pack(side='left')

second = Label(first, text='Начальная скорость')
second.pack()

entry1 = Entry(first, width=10, textvariable=v)
entry1.pack()

third = Label(first, text='Угол выстрела')
third.pack()

entry2 = Entry(first, width=10, textvariable=an)
entry2.pack()


first = LabelFrame(root, text='Расчет')
first.pack(side='right')
dp1 = Label(first, text='Дальность полета 1 тела')
dp1.pack()
dp1o = Label(first, text='')
dp1o.pack()


button = Button(root, text="Сгенерировать", command=analysis)
button.pack(side='left')

root.mainloop()