我决定尝试 Python 和 Tkinter 作为第一个项目。单击相关按钮时,我无法更改变量。到目前为止,我已经搜索了 3 天,但还没有找到我需要什么来执行我的程序的“def Next”部分。对不起,我的代码是一团糟。对此进行编码的任何提示和快捷方式都值得赞赏。代码的最终结果应执行,例如 iwconfig wlan1 txpower 20。
#!/usr/bin/python
# First Python & Tkinter project
# K. Silva
# Setup interface buttons and functions
global interface
interface = "wlan0"
global cardpower
cardpower = "0"
import os
# Clear screen
os.system("clear")
# Set geo for wireless card power
os.system("sudo iw reg set BO")
# List interfaces
os.system("iwconfig")
# Begin GUI coding
from Tkinter import *
master = Tk()
master.title('Wireless Warrior')
def Wla0():
interface = "wlan0"
print interface
def Wla1():
interface = "wlan1"
print interface
def Wla2():
interface = "wlan2"
print interface
def Wla3():
interface = "wlan3"
print interface
def Wla4():
interface = "wlan4"
print interface
def Wla5():
interface = "wlan5"
print interface
def Wla6():
interface = "wlan6"
print interface
w = Label(master, text="Wireless Warrior", fg="blue", font=("Helvetica", 16))
w.grid(row=0, column=0, columnspan=3)
Wl0 = Button(master, text="Wlan0", width=4, command=Wla0)
Wl0.grid(row=1,column=0)
Wl1 = Button(master, text="Wlan1", width=4, command=Wla1)
Wl1.grid(row=2,column=0)
Wl2 = Button(master, text="Wlan2", width=4, command=Wla2)
Wl2.grid(row=3,column=0)
Wl3 = Button(master, text="Wlan3", width=4, command=Wla3)
Wl3.grid(row=4,column=0)
Wl4 = Button(master, text="wlan4", width=4, command=Wla4)
Wl4.grid(row=5,column=0)
Wl5 = Button(master, text="wlan5", width=4, command=Wla5)
Wl5.grid(row=6,column=0)
Wl6 = Button(master, text="wlan6", width=4, command=Wla6)
Wl6.grid(row=7,column=0)
# Setup power buttons and functions
def Half():
cardpower = "20"
print cardpower
def One():
cardpower = "30"
print cardpower
def OneFive():
cardpower = "31"
print cardpower
def Two():
cardpower = "33"
print cardpower
def Three():
cardpower = "34"
print cardpower
def Five():
cardpower = "36"
print cardpower
def FiveEight():
cardpower = "37"
print cardpower
half = Button(master, text="500mW", width=4, command=Half)
half.grid(row=1,column=1)
one = Button(master, text="1W", width=4, command=One)
one.grid(row=2,column=1)
onefive = Button(master, text="1.5W", width=4, command=OneFive)
onefive.grid(row=3,column=1)
two = Button(master, text="2W", width=4, command=Two)
two.grid(row=4,column=1)
three = Button(master, text="3W", width=4, command=Three)
three.grid(row=5,column=1)
five = Button(master, text="5W", width=4, command=Five)
five.grid(row=6,column=1)
fiveeight = Button(master, text="5.8W", width=4, command=FiveEight)
fiveeight.grid(row=7,column=1)
def Next():
print "iwconfig " + interface + " txpower " + cardpower
#os.system("sudo iwconfig " + interface + " txpower " + (cardpower))
next = Button(master, text="Next",width=4, command=Next)
next.grid(row=7,column=3)
mainloop()