3

私はここ数週間、産業用ロボットとワイヤレス接続を行い、RESTプロトコルを使ってRaspberry PiとPythonを使ってプロジェクトを進めています。私はPythonに慣れていませんが、C++に精通していますので、必ずプログラミングに新しいことはありません。Pythonの入力行はキーボードの入力を得られません - 代わりに端末の種類

私はPythonでTkinterを使用してGUIを作成しました。あなたの助けてくれてありがとうございます。キオスクモードのようなものを作成しようとしています。私は既にGUIをフルスクリーンで起動し、それを閉じるオプションはありません。私が固執しているのは、正しいパスワード文字列が入力されたときに、管理者のためのGUIを閉じたり、残りの部分にアクセスできるように権限を与えられた個人が入力する、GUIのポップアップウィンドウの1つにエントリ行を作成しようとしていることです。必要に応じて、Raspberry Piファイルのroot.quit()メソッド(親ウィンドウはルート)を使ってこのプロセスを動作させる方法を知っていると思いますが、エントリ行にはテキストも表示されません。私のGUIがフルスクリーンであっても、入力したすべてのテキストがターミナルに入力されています。ここで私がであることをエントリ行を取得しようとしていますポップアップウィンドウのコメントとコードの特定のセクションには、次のとおりです。

################## Status Window ################## 
def statusWindow():              #defines function for popup window for additional options 
    window = Toplevel(root)            #creates variable to place widgets in window 
    window.title('Status')            #makes window title for specific window frame 
    w, h = window.winfo_screenwidth(), window.winfo_screenheight()  #aquires dimensions from display size 
    window.geometry("%dx%d+0+0" % (w, h))        #sets window size to aquired dimensions 
    window.overrideredirect(True)          #removes top bar and exit button from parent window frame 

    batteryButton = Button(window, text="Battery", fg="green", command=lambda: showBattery(window), width=35, height=12)  #defines criteria for battery button in new window 
    statusButton = Button(window, text="Overview", fg="green", command=lambda: showQueueStatus(window), width=35, height=12) #defines criteria for status button in new window 
    returnButton = Button(window, text="Return...", fg="green", command=window.destroy, width=35, height=12)     ##defines criteria for return button in new window 
    passEntry = Entry(window, show="*") 

    batteryButton.grid(row=1, column=0, padx=10, pady=5)  #makes button viewable in specified orientation                 
    statusButton.grid(row=2, column=0, padx=10, pady=5)   #makes button viewable in specified orientation 
    returnButton.grid(row=3, column=0, padx=10, pady=5)   #makes button viewable in specified orientation 
    passEntry.grid(row=4, columnspan=10, sticky=W) 

    robotName(window)  #call robotName function to display robot name 
    winReturn(window)  #call winReturn function to create return label 

def robotName(winFrame):        #define function to display robot name in status window 
    label = Label(winFrame, text="Robot Name: ")  #defines variable label for visual display 
    name = robot.robot_name()       #gets robot name from robot and stores it in name variable 
    nameLabel = Label(winFrame, text=name)    #defines variable label for visual to hold robot name as string   

    label.grid(row=0, column=0, padx=10, pady=5)  #makes label display in popup window 
    nameLabel.grid(row=0, column=3, padx=10, pady=5) #makes robot name display in popup window 

def showBattery(winFrame):         #define function to display current battery percentage in popup window 
    battery = robot.battery_percentage()     #retrieves current battery status from robot and stores it in battery variable 
    battery = str(battery) + '%'       #redefines battery variable as previous battery variable string with percentage 
    batteryLabel = Label(winFrame, text=battery)   #defines battery label with specified criteria 
    batteryLabel.grid(row=1, column=3, padx=10, pady=5)  #displays battery label in popup window 

def showQueueStatus(winFrame):        #define function to display current robot mission queue item status 
    queue = robot.robot_state_text()      #retrieves current queue item status and stores in queue variable 
    qStatusLabel = Label(winFrame, text=queue)    #defines queue status label with specified criteria 
    qStatusLabel.grid(row=2, column=3, padx=10, pady=5)  #displays queue status label in popup window 

def winReturn(winFrame):          #define function to display label for return button 
    returnLabel = Label(winFrame, text="Close out of window") #defines return label with specified criteria 
    returnLabel.grid(row=3, column=3, padx=10, pady=5)   #displays return label in popup window 

これはメソッドであるように私はstatusWindow()の定義にエントリーラインを配置していますそれは私のプログラムの残りの部分から呼び出されます。私がエントリーラインに入力しないようにする理由があれば、あなたのアドバイスをいただければ幸いです。私のコードのサンプルが必要な場合は、私はもっとポストすることができますが、私はこのポストを短くしています。

+0

こんにちはJ.Kors。ここにはたくさんのコードがありますが、あなたが[最小限で完全であり、検証可能な例](https://stackoverflow.com/help/mcve)を提供できるのが最善でしょう。あなたのコードにこの問題を引き起こす何かが存在する可能性があります。MCVEを作成すると、あなた自身で問題が見つかるかもしれません。それでも問題が解決しない場合は、私たちがテストするための何かを提供します。 –

+0

私のコードには、ユーザーのテキストを入力行に入力することを禁止する何かがあることに私は同意します。私はエントリーラインだけでうまく動作するもう少し小さなプログラムを作りました。私の推測では、それは私が使用しているTkinterフレームと関係があることです。ウィジェットの焦点になるのだろうか? –

+0

これまで入力したコードでは、ユーザーが入力フィールドではなくコンソールに入力する可能性があります。ユーザーはマウスを操作しているのですか、それともタッチスクリーンベースですか? –

答えて

2

を試すなど、パスワードチェック機能を呼び出す何をすべきかあなたの決定をするために

passEntry.bind('<Return>', myfunc) 

を行うことができますあなたのプログラムがどのように動作しているかを見ると、管理者のアクセスを求めるためにトップレベルのウィンドウを作成する必要はありません。 tkinters simpledialog askstring関数を使用してパスワードを要求し、iconify()を使用してウィンドウを最小化することができます。

この例を見てください。

from tkinter import * 
from tkinter import simpledialog 
# from Tkinter import * # for python 2.x 
# import tkSimpleDialog as simpledialog # for python 2.x 

root = Tk() 
root.attributes("-fullscreen", True)# fullscreen without the standard window buttons 

def check_admin_password(): 
    # use askstring here to verify password. 
    pass_attempt = simpledialog.askstring("Verifying access", 
              "Please enter Admin password") 
    if pass_attempt == "password": 
     root.iconify() # used whatever your instance of Tk() is here in place of root. 

admin_minimize_button = Button(root, text = "Minimize window", command = check_admin_password) 
admin_minimize_button.pack() 

root.mainloop() 
+0

私はこのコードを試してみましたが、私はそれを単独で実行しようとしたときにエラーを出しましたそれはsimpledialogをインポートできませんでした。私は輸入ラインをコメントし、最小限のボタンで開きましたが、コマンドやメソッドは呼び出されませんでした。私はそれができなかったので起こったと仮定していますimport simplenialog。 –

+0

@ J.korsどのバージョンのpythonを使用していますか? –

+0

私はRaspberry Pi 3でpython 2.7を使用しています。上のあなたの他のコメントに応えて、私はforce_focus()を使ってみました。 –

0

あなたは、フルスクリーンのGUIを非表示にする必要がある場合は、なしで

root.tk.call('wm', 'withdraw', root) 
関連する問題