Автопечатка Проблема в виджете ввода при приеме записи во второй раз - PullRequest
0 голосов
/ 23 января 2020

Здесь, в моем проекте, я создал 4 элемента ввода, чтобы получать значения от пользователя после того, как пользователь выбрал опцию «mode». Когда я запускаю свой код, он работает правильно в первый раз, если пользователь снова выбирает «режим» и задает значения в виджете ввода, то для 1-го виджета двух входов принимаются значения согласно коду, но возникает проблема при задании значений в 3-м виджете ввода, и Проблема в том, что «что бы ни печаталось в 3-м виджете, оно автоматически вводится в 4-м виджете ввода». Я совершенно не знаком с python и переполнением стека. Так что, если есть какая-либо ошибка в вопросе, тогда, пожалуйста, помогите мне. Вот мой код

import tkinter as tk
import threading
import time
from time import sleep
root=tk.Tk()
root.geometry("600x600")
root.title("User Interface Monitor")
rpm=tk.IntVar()
tor=tk.IntVar()
tim=tk.IntVar()
tim1=tk.IntVar()
def  enter():
    global rpm,tor,tim,tim1
    root.rpmLabel=tk.Label(root,text="enter rpm value:")
    root.rpmLabel.grid(row=0)
    root.torLabel = tk.Label(root, text="enter Torque value:")
    root.torLabel.grid(row=1)
    root.timeLabel=tk.Label(root,text="enter  Ramp time in secs: ")
    root.timeLabel.grid(row=2)
    root.timeLabel1 = tk.Label(root, text="enter  steady time in secs:")
    root.timeLabel1.grid(row=3)
    root.e1 = tk.Entry(root, textvariable=rpm)
    root.e1.grid(row=0, column=1)
    root.e1.delete(0,"end")
    root.e2 = tk.Entry(root, textvariable=tor)
    root.e2.grid(row=1, column=1)
    root.e2.delete(0, "end")
    root.e3 = tk.Entry(root, textvariable=tim)
    root.e3.grid(row=2, column=1)
    root.e3.delete(0, "end")
    root.e4 = tk.Entry(root, textvariable=tim1)
    root.e4.grid(row=3, column=1)
    root.e4.delete(0, "end")

def gett():
    global rpm, tor, tim, tim1
    rpm = int(root.e1.get())
    tor= int(root.e2.get())
    tim = float(root.e3.get())
    tim1 = float(root.e4.get())
    print("rpm is :", rpm)
    print("Torque is :", tor)
    print("ramp time is :", tim)
    print("steady time is :", tim1)
    root.rpmLabel.destroy()
    root.e1.destroy()
    root.torLabel.destroy()
    root.e2.destroy()
    root.timeLabel.destroy()
    root.e3.destroy()
    root.timeLabel1.destroy()
    root.e4.destroy()
    t1=threading.Thread(target=getRpm,daemon=True)
    t2=threading.Thread(target=getTor,daemon=True)
    t1.start()
    t2.start()
def getRpm():
    global rpm,tim,tim1,t
    st=0
    x=0
    val=int((rpm/2))
    for i in range(0,val+1,1):
        y=time.ctime()
        y=y[10:-4]
        if i==0:
            st=y
        sleep(0.001)
        x=i
    dell =time.ctime()
    dell=dell[10:-4]
    sleep(tim1)
    y=time.ctime()
    y=y[10:-4]
    print(st, x, dell, y)
def getTor():
    global tor,tim,tim1
    start=0
    b=0
    a=int(4096*(tor/100))
    for j in range(0,a+1,1):
        c=time.ctime()
        c=c[10:-4]
        if j==0:
            start=c
        sleep(0.001)
        b=j
    delta=time.ctime()
    delta=delta[10:-4]
    sleep(tim1)
    c=time.ctime()
    c=c[10:-4]
    print(start,b,delta,c)

root.Button1=tk.Button(root,text="MODE1",bg="red",command=enter)
root.Button1.pack()
root.Button1.place(x=100,y=200)
root.Button2=tk.Button(root,text="MODE2",bg="red",command=enter)
root.Button2.pack()
root.Button2.place(x=100,y=230)
root.Button3=tk.Button(root,text="Enter",command=gett)
root.Button3.pack()
root.Button3.place(x=160,y=215)
root.mainloop()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...