# coding:utf-8
from Tkinter import *
import os, sys, re, commands, tkMessageBox
# 模拟网卡
Netlist = ['A1', 'B2','C3','D4','E5','F6',None]
bond = None
Clb = None
Vlan = None
vlanip_set = None
vlan_prefix_length = None
gateway_set = None
#网卡
def network():
root1 = Tk()
root1.geometry('300x300+600+150')
root1.title('网卡选择')
lb = Listbox(root1) # 创建列表框
lb.focus_set()
def CallOn(event):
global Clb
Clb = lb.get(lb.curselection())
#Clb.focus_set()
print(Clb)
if Clb in Netlist:
bfile = open('\Users\Administrator\Desktop\ifcfg-bond-%s' % bond, 'w+')
bfile.write('TYPE=Ethernet\nBOOTPROTO=none\nNAME=%s\nDEVICE=%s\nONBOOT=yes\nBONDING_OPTS="mode=4 miimon=100 xmit_hash_policy=layer3+4"' % (bond, bond))
bfile.close()
dfile = open('\Users\Administrator\Desktop\ifcfg-bond-%s' % Clb, 'w+')
dfile.write('TYPE=Ethernet\nBOOTPROTO=none\nNAME=%s\nDEVICE=%s\nONBOOT=yes\nMASTER=%s\nSLAVE=yes' % (Clb, Clb, bond))
dfile.close()
root1.destroy()
network_2()
root1.quit()
def Quit(a):
print('退出')
root1.destroy()
#vlan_Set()
#quit()
label = Label(root1,text = 'Choice Net-Device join to %s\nNetwork-Device List:' % bond,fg = 'red')
#双击命令
lb.bind('<Double-Button-1>',CallOn)#列表框绑定双击命令,回调函数
lb.bind_all("<KeyPress-Return>", CallOn)#列表框激活回车命令
frame = Frame(root1,width = 300,height = 50)
button1 = Button(frame,text = '退出')
button1.bind("<Button-1>", Quit)
frame.pack(side = BOTTOM,)
button1.pack(side = RIGHT)
global Netlist
Netlist.remove(Clb)
for i in Netlist:#向列表框中添加元素
lb.insert(END,i)#向列表后添加遍历元素
label.pack()#标签显示
lb.pack()#列表显示
root1.mainloop()#父窗口显示
#网卡选择2
def network_2():
root1 = Tk()
root1.geometry('300x300+600+150')
root1.title('网卡选择')
lb = Listbox(root1) # 创建列表框
lb.focus_set()
def CallOn(event):
global Clb
Clb = lb.get(lb.curselection())
print(Clb)
if Clb in Netlist:
bfile = open('\Users\Administrator\Desktop\ifcfg-bond-%s' % bond, 'w+')
bfile.write('TYPE=Ethernet\nBOOTPROTO=none\nNAME=%s\nDEVICE=%s\nONBOOT=yes\nBONDING_OPTS="mode=4 miimon=100 xmit_hash_policy=layer3+4"' % (bond, bond))
bfile.close()
dfile = open('\Users\Administrator\Desktop\ifcfg-bond-%s' % Clb, 'w+')
dfile.write('TYPE=Ethernet\nBOOTPROTO=none\nNAME=%s\nDEVICE=%s\nONBOOT=yes\nMASTER=%s\nSLAVE=yes' % (Clb, Clb, bond))
dfile.close()
root1.destroy()
network()
root1.quit()
def Quit(a):
print('退出')
root1.destroy()
#vlan_Set()
#quit()
label = Label(root1,text = 'Choice Net-Device join to %s\nNetwork-Device List:' % bond,fg = 'red')
#双击命令
lb.bind('<Double-Button-1>',CallOn)#列表框绑定双击命令,回调函数
lb.bind_all("<KeyPress-Return>", CallOn)#列表框激活回车命令
frame = Frame(root1,width = 300,height = 50)
button1 = Button(frame,text = '退出')
button1.bind("<Button-1>", Quit)
frame.pack(side = BOTTOM,)
button1.pack(side = RIGHT)
global Netlist
Netlist.remove(Clb)
for i in Netlist:#向列表框中添加元素
lb.insert(END,i)#向列表后添加遍历元素
label.pack()
lb.pack()
root1.mainloop()
network()