下記のようなツールを
Lubuntu 16.04 Pythonで動かせているのですが、これを起動している間ずっとウィンドウの後ろで、ターミナルが起動したままなのですが、ターミナルを表示させないようにするにはどうしたらいいでしょうか?
python
1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3 4# ++++++++++++++++++++++++++++++++++++++++ モジュール +++++ 5from tkinter import * 6from tkinter import ttk 7from time import * 8import subprocess 9 10# ++++++++++++++++++++++++++++++++++++++++ ウィンドウ +++++ 11root = Tk() 12root.geometry('350x200') 13root.title('USB給電制御') 14root.option_add('*font', ('Helvetica', 10)) 15root.resizable(0,0) 16 17# ++++++++++++++++++++++++++++++++++++++++ 関 数 +++++ 18# 現在時刻の処理 19def CurrentTime(): 20 # グローバル変数を指定 21 global currentTime 22 global onTime 23 global offTime 24 # 現在時刻をセットする 25 currentTimeVal.set(strftime('%H:%M:%S')) 26 # ON/OFF時間を代入する 27 onHour = onHourVal.get() 28 onMin = onMinVal.get() 29 onSec = onSecVal.get() 30 offHour = offHourVal.get() 31 offMin = offMinVal.get() 32 offSec = offSecVal.get() 33 # 現在・ON/OFF時間をグローバル変数に代入する 34 currentTime = currentTimeVal.get() 35 onTime = onHour + ':' + onMin + ':' + onSec 36 offTime = offHour + ':' + offMin + ':' + offSec 37 # 一定時間で繰り返す 38 root.after(1000, CurrentTime) 39 40# ON/OFFの処理 41def powerProc(power): 42 # コマンドリストを初期化 43 cmdList = [] 44 # 選択されているHUB名称を取得 45 hubName = hubNameVal.get() 46 # HUB選択で初期項目(選択してください)だった場合 47 if hubName == initialHubName: 48 return 49 # コマンドリストを作成する 50 for i in retList: 51 # バス・デバイス・ポート番号を取り出す 52 bus = i[4:7].lstrip('0') 53 device = i[15:18].lstrip('0') 54 port = portVal.get() 55 # マッチングするリスト番号を特定 56 if i.find(hubName) > -1: 57 matchIndex = retList.index(i) 58 # コマンドに当てはめてリストに保存する 59 cmdList.append('sudo /opt/hub-ctrl/hub-ctrl -b ' + bus + ' -d ' + device + ' -P ' + port + ' -p ' + power) 60 # コマンドを実行する 61 subprocess.call(cmdList[matchIndex], shell=True) 62 63# ONタイマーの処理 64def OnTimer(): 65 # ONタイマーにチェックが入っている場合 66 if onVal.get(): 67 # ONタイマーの時刻と現在時刻が一致した場合 68 if onTime == currentTime: 69 # ON 70 power = '1' 71 powerProc(power) 72 # 一定時間で繰り返す 73 root.after(1000, OnTimer) 74 75# OFFタイマーの処理 76def OffTimer(): 77 # OFFタイマーにチェックが入っている場合 78 if offVal.get(): 79 # ONタイマーの時刻と現在時刻が一致した場合 80 if offTime == currentTime: 81 # OFF 82 power = '0' 83 powerProc(power) 84 # 一定時間で繰り返す 85 root.after(1000, OffTimer) 86 87# 強制ONの処理 88def ForceOn(): 89 # ON 90 power = '1' 91 powerProc(power) 92 93# 強制OFFの処理 94def ForceOff(): 95 # OFF 96 power = '0' 97 powerProc(power) 98 99# ++++++++++++++++++++++++++++++++++++++++ 初期動作 +++++ 100# 管理者権限の取得 101 102# 入力コマンドのセット 103cmd = 'sudo lsusb' 104ret = subprocess.check_output(cmd, shell = True) 105# 結果をデコードしてStringに変換 106decRet = ret.decode('utf-8') 107# 最後の\nを削除 108slcRet = decRet[:-1] 109# \nで区切ってリストに入れる 110retList = slcRet.replace("'","").split('\n') 111# 区切ったリストの文字からBus・Device・IDを削除する 112retNameList = [val[33:] for val in retList] 113 114# ++++++++++++++++++++++++++++++++++++++++ 変 数 +++++ 115# ラベル 116currentTimeVal = StringVar() 117 118# コンボボックス 119hubNameVal = StringVar() 120initialHubName = '選択して下さい' 121hubNameVal.set(initialHubName) 122 123# チェックボックス 124onVal = BooleanVar() 125offVal = BooleanVar() 126onVal.set(True) 127offVal.set(True) 128onCheck = '' 129offCheck = '' 130 131# スピンボックス 132portVal = StringVar() 133onHourVal = StringVar() 134onMinVal = StringVar() 135onSecVal = StringVar() 136offHourVal = StringVar() 137offMinVal = StringVar() 138offSecVal = StringVar() 139onHourVal.set('06') 140onMinVal.set('00') 141onSecVal.set('00') 142offHourVal.set('18') 143offMinVal.set('30') 144offSecVal.set('00') 145 146# その他 147currentTime = '' 148onTime = '' 149offTime = '' 150 151# ++++++++++++++++++++++++++++++++++++++++ リスト +++++ 152# コマンド 153cmdList = [] 154 155# ラベル 156labelPositions = [ 157 {'text' : '現在時刻', 'textvariable' : '', 'x' : 30, 'y' : 20}, 158 {'text' : '対象HUB/Port', 'textvariable' : '', 'x' : 30, 'y' : 50}, 159 {'text' : ':', 'textvariable' : '', 'x' : 169, 'y' : 80}, 160 {'text' : ':', 'textvariable' : '', 'x' : 218, 'y' : 80}, 161 {'text' : ':', 'textvariable' : '', 'x' : 169, 'y' : 110}, 162 {'text' : ':', 'textvariable' : '', 'x' : 218, 'y' : 110}, 163 {'text' : '', 'textvariable' : currentTimeVal, 'x' : 135, 'y' : 20} 164] 165 166# コンボボックス 167comboboxPositions = [ 168 {'values' : retNameList, 'textvariable' : hubNameVal, 'state' : 'readonly', 'width' : 17, 'x' : 135, 'y' : 50} 169] 170 171# ボタン 172buttonPositions = [ 173 {'text' : '強制ON', 'command' : ForceOn, 'width' : 8, 'x' : 135, 'y' :150}, 174 {'text' : '強制OFF', 'command' : ForceOff, 'width' : 8, 'x' : 235, 'y' :150} 175] 176 177# チェックボックス 178checkButtonPositions = [ 179 {'varName' : onCheck, 'text' : 'ONタイマー', 'variable' : onVal, 'x' : 30, 'y' : 80}, 180 {'varName' : offCheck, 'text' : 'OFFタイマー', 'variable' : offVal, 'x' : 30, 'y' : 110} 181] 182 183# スピンボックス 184spinBoxPositions = [ 185 {'from' : 1, 'to' : 4, 'increment' : 1, 'format' : '', 'textvariable' : portVal,'with' :2, 'x' : 285, 'y' : 50}, 186 {'from' : 0, 'to' : 23, 'increment' : 1, 'format' : '%02.0f', 'textvariable' : onHourVal, 'with' :2, 'x' : 135, 'y' : 80}, 187 {'from' : 0, 'to' : 59, 'increment' : 1, 'format' : '%02.0f', 'textvariable' : onMinVal, 'with' :2, 'x' : 185, 'y' : 80}, 188 {'from' : 0, 'to' : 59, 'increment' : 1, 'format' : '%02.0f', 'textvariable' : onSecVal, 'with' :2, 'x' : 235, 'y' : 80}, 189 {'from' : 0, 'to' : 23, 'increment' : 1, 'format' : '%02.0f', 'textvariable' : offHourVal, 'with' :2, 'x' : 135, 'y' : 110}, 190 {'from' : 0, 'to' : 59, 'increment' : 1, 'format' : '%02.0f', 'textvariable' : offMinVal, 'with' :2, 'x' : 185, 'y' : 110}, 191 {'from' : 0, 'to' : 59, 'increment' : 1, 'format' : '%02.0f', 'textvariable' : offSecVal, 'with' :2, 'x' : 235, 'y' : 110} 192] 193 194# ++++++++++++++++++++++++++++++++++++++++ オブジェクトの配置 +++++ 195# ラベル 196for i in labelPositions: 197 Label(root, text = i['text'], textvariable = i['textvariable']).place(x = i['x'], y = i['y']) 198 199# コンボボックス 200for i in comboboxPositions: 201 ttk.Combobox(root, values = i['values'], textvariable = i['textvariable'], state = i['state'], width = i['width']).place(x = i['x'], y = i['y']) 202 203# ボタン 204for i in buttonPositions: 205 Button(root, text = i['text'], command = i['command'], width = i['width']).place(x = i['x'], y = i['y'] ) 206 207## チェックボックス 208for i in checkButtonPositions: 209 i['varName'] = Checkbutton(text = i['text'], variable = i['variable']).place(x = i['x'], y = i['y']) 210 211# スピンボックス 212for i in spinBoxPositions: 213 Spinbox(root, from_ = i['from'], to = i['to'], increment = i['increment'], format = i['format'], textvariable =i['textvariable'], width = i['with']).place(x = i['x'], y = i['y'] ) 214 215# ++++++++++++++++++++++++++++++++++++++++ 関 数 +++++ 216# 現在時刻 217CurrentTime() 218 219# ONタイマー 220OnTimer() 221 222# OFFタイマー 223OffTimer() 224 225# ++++++++++++++++++++++++++++++++++++++++ ウィンドウ表示 +++++ 226root.mainloop() 227
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。