将多个字符串写入变量(Python)

时间:2018-07-19 08:31:13

标签: python lan netsh

我正在尝试使用Python和Tkinter模块制作一个Python NetSH网络制造商,目前我在制定程序将要执行的最终批处理文档时,如何将条目合并在一起。请参阅“ e1”部分的开头以了解我的问题。

我的目的是从用户那里获得两个条目并将它们写入一个批处理文件,以使用计算机的网卡建立一个wlan网络。我也尝试过分别引用变量,这也给了错误。

#Simple GUI
#Import Tkinter
from tkinter import *
import tkinter.messagebox
import os
import subprocess
from subprocess import Popen

#Window
master = Tk()

#Modify Root Window
master.title("Simple GUI")
master.geometry("640x420")

Label(master, text="Network Name").grid(row=0, column=0)
Label(master, text="Network Password").grid(row=4, column=0)

e1 = Entry(master)
e2 = Entry(master)

e1.grid(row=1, column=0)
e2.grid(row=5, column=0)

e3 = (e1, " key=", e2)

# Secondary Window
def success():
   tkinter.messagebox.showinfo("Success", "WiFi Network created!\n\nThe Wifi 
Network will end once the computer is restarted or shut down")

#CMD Command
def run():
    text_file = open("wifi.txt", "w")
    text_file.write("netsh wlan set hostednetwork mode=allow ssid=")
    text_file.write(e3)
    text_file.write("\nnetsh wlan start hostednetwork")
    text_file.close()



Button(master, text='Generate', command = run).grid(row=6, column=0, 
sticky=N, pady=2)


#Making a label
master = Frame(master)
master.grid()
label2 = Label(master, text = "This is a baisc Python program using the 
Tkinter GUI interface \n to successfully execute bash code in the Command 
Prompt to make a WiFi Network using your laptop's Network Card.")
label2.grid(row=10, column=0)

#Button 'Help'
def info():
    tkinter.messagebox.showinfo()
B1 = tkinter.Button(master, text ="info", relief=RAISED,\
                         bitmap="info")
B1.grid()



#Text Writing
def writeFile():
    file = open('command.bat')
    file.write(metinF.get() + '\n')
    file.close()


'''
#Button
button1 = Button(app, text = "Generate")
button1.grid()

button2 = Button(app)
button2.grid()

button2.configure(text = "Decline")

button3 = Button(app)
button3.grid()

button3["text"] = "Help"
'''

#Label 2
app = Frame(master)
app.grid()
label2 = Label(app, text = "\n Made by Christopher Grainger \n 2018")
label2.grid()

#Kick Event
master.mainloop()

请提供帮助,因为此错误非常令人困惑,甚至Google对此也没有任何有效的解决方案。我尝试过在线列出的内容,但它们也有自己的错误。

谢谢;

克里斯 appleosophy.com @appleosophy

1 个答案:

答案 0 :(得分:0)

您试图将元组写入文件。但是write方法仅将字符串作为争论。使用

checkboxItem

运行功能内部。 get方法以字符串形式返回条目中的输入。