2017-01-12 13 views
-3

私は3日前にpythonを手に取りました。私はプログラムを作成中です。これは私にとってはプログラミングの面白さでもあります。私は学ぶために不毛の銘持ちの時間を過ごしました、そして、これまで私は自分の道を進んできましたが、私は立ち往生しているのでしょうか?tkinterのエントリウィジェットの文字列を引っ張るエラー

私は作成したGPIO機能を制御するためのGUIを作成中です。作成したGPIO関数を使用するだけで、いくつかのライトが点滅します。当面は、ユーザー入力遅延とtkinterのEntryウィジェットを使用してユーザーが入力したループ数の2つのLEDが同時に点滅します。これは私の問題が発生した場所で、Entryウィジェットから入力を取得しようとすると 'str'エラーが発生します。これは、エントリが文字列データ型であり、点滅関数が整数データ・タイプ?しかし、これを整数にすると、 "literal int()base 10"のエラープロンプトが表示されます。助けてください。

免責事項:

は、ここに私の現在のスクリプトで、いくつかの構文エラーがあるかもしれません。 Deereのファイアウォールは私がネットワークに接続することを許可しないので、私はこのすべてをもう一度タイプしなければならなかった。

import tkinter as tk 
root=tk.Tk() 
root.title("LED Controller") 
import sys 
import RPi.GPIO as GPIO 
import time 
GPIO.setwarnings(False) 
GPIO.setmode(GPIO.BOARD) 
GPIO.setup(7, GPIO.OUT) 
GPIO.setup(11,GPIO.OUT) 

CycleLabel = tk.Label(root, text="Cycles", font="Verdana 12 bold") 
CycleLabel.grid(row=1,column=1) 
CycleInput = tk.Entry(root) 
CycleInput.grid(row=1,column=2) 
CycleInput.focus_set() 
cycle=CycleInput.get() 

SpeedLabel = tk.Label(root, text="Speed", font="Verdana 12 bold") 
SpeedLabel.grid(row=1,column=1) 
SpeedInput = tk.Entry(root) 
SpeedInput.grid(row=2,column=2) 
SpeedInput.focus_set() 
speed = SpeedInput.get() 

def callback(): 
    print (CycleInput.get()) 
    print (SpeedInput.get()) 

def Blink(cycle,speed): 
    for platypus in range (0, cycle):   ** This is the line that the error always points to. 
     print("Loop" + str(platypus+1)) 
     GPIO.output(7,True) 
     GPIO.output(11, True) 
     time.sleep(speed) 
     GPIO.output(7, False) 
     GPIO.output(11, False) 
     time.sleep(speed) 
     print("Done") 

ButtonFrame = tk.Frame(root) 
ButtonFrame.grid(row=3,column=1,columnspan=3) 

B2 = tk.Button(ButtonFrame, text="Start", width=10, command=lambda:Blink(cycle,speed), font="Verdana 10 bold") 
B2.grid(row=3,column=2) 

B1 = tk.Button(ButtonFrame, text"Print Inputs", width=10, command=callback, font="Verdana 10 bold") 
B1.grid(row=3,column=1) 

def clear(): 
    CycleInput.delete(0, 'end') 
    SpeedInput.delete(0, 'end') 

B3 = tk.Button(ButtonFrame, text="Clear", width=10, command=clear, font="Verdana 10 bold") 
B3.grid(row=3,column=3) 

CloseFrame = tk.Frame(root) 
CloseFrame.grid(row=4, column=1, columnsapn=3) 

B4 = tk.Button(CloseFrame, text="Close", width=20, command=root.destroy, font="Verdana 10 bold", activebackground='red') 
B4.grid(row=4,column=2) 
+0

あなたは答えを探しましたか?あなたの質問には研究の兆候は見られません。 '[tkinter] gpio'を検索することから始めましょう。私はこれを書いている時点で58の質問がありますが、そのうちのいくつかはおそらくこの質問によく似ています。 –

+0

私の質問にはGPIOは関係しません。 – Raudert

+0

助けてくれてありがとう! :) – Raudert

答えて

1
command=lambda:Blink(cycle,speed) 

あなたcyclespeed変数は、すぐに対応するエントリのフィールドを作成した後、正確に一度設定しました。したがって、それらは常に空文字列になります。ユーザはそれらの値を入力する機会が全くありませんでした。ボタンをクリックした後に.get()を実行する必要があります。このラムダまたはBlinkのいずれかです。

また、入力された文字列をintに変換し、入力された文字列が有効なintではない可能性も処理する必要があります。

関連する問題