謝謝您的幫助!到目前為止我的進展... 問題: 1 - 當按下開始按鈕時,我需要程式存盤用戶輸入的值。2 - 我需要步進器保持旋轉并停在特定方向。這是我的代碼:
https://pastebin.com/2wcwpZx5
import random
from itertools import count
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import tkinter as tk
from time import sleep
uj5u.com熱心網友回復:
我不得不移動很多東西。由于我不熟悉原始代碼的所有背景關系,因此可能仍然存在一些問題。但是,希望它足夠好,您可以了解如何實作您的目標。
from tkinter import *
from pymata4 import pymata4
top = Tk()
top.geometry("450x300")
pins = [8,9,10,11]
board = pymata4.Pymata4()
# These variables need to be declared to be in the global space.
angularvelocity = 0.0 # I assumed this is a float type.
numsteps = 0 # I assumed this is an int type.
complete = False # I added this to show how to stop running.
def actuate():
global angularvelocity, numsteps, complete
board.stepper_write(angularvelocity, numsteps)
if complete:
pass
else:
top.after(1000, actuate) # This will run actuate after 1000 ms
def set_input():
global pins, angularvelocity, numsteps
angularvelocity = angular_velocity_var.get() # run .get() on DoubleVar object instead
numsteps = num_steps_var.get() # run .get() on IntVar object instead
board.set_pin_mode_stepper(numsteps, pins) # it was num_steps?
actuate()
num_steps = Label(top, text="Steps").place(x=40, y=60)
angular_velocity = Label(top, text="Angular Velocity").place(x=40,y=100)
# Button requires a command definition or it is just for looks
submit_button = Button(top, text ="Submit" command=set_input).place(x=40,y=130)
num_steps_var = IntVar() # These are tkinter built in. There is also a StringVar
num_steps_input_area = Entry(top, width=30, textvariable=num_steps_var).place(x=180,y=60)
angular_velocity_var = DoubleVar() # and a BooleanVar
angular_velocity_input_area = Entry(top, width=30, textvariable=angular_velocity_var).place(x=180, y=100)
top.mainloop()
請讓我知道這對你有沒有用。我沒有運行這個。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/477659.html
