前面写了一个简单的管理电脑创建的WIFI热点的工具,整体比较简单,只是由一个图片,和2个button,还有一个MessageBox组成,这两天又完善了下,主要更新了以下几个方面:

1.使用类来编写代码(由于自己基本还是面向过程思想,有必要学习下类的基本写法)

2.将版本1中的MessageBox改为由ListBox和Scrollbar组成的frame,这样信息可以一直显示在listbox里面。

3.增加了菜单栏,并添加了一些子菜单。

4.程序窗口固定,退出需用户确认。

下面是源代码:

# -*- coding: utf-8 -*-
#author: Cullen#import the needed module
from Tkinter import *
import tkFont
import tkMessageBox
import os
from PIL import ImageTk, Imagedef close_window(window):"""give prompt when user close the window"""if tkMessageBox.askyesno("QUIT", "Close the Window(Yes/No)", icon="question"):window.destroy() def manage_wifi(how, message_frame):"""this function will open/close the wifi network accoring the arguments:how=1(open the network) how=2(close the network),message_frame(the frame which the message display"""open_wifi_cmd = "netsh wlan start hostednetwork"close_wifi_cmd = "netsh wlan stop hostednetwork"if how == 1:cmd = open_wifi_cmdelse:cmd = close_wifi_cmdresult = os.system(cmd)if result != 0:if how == 1:message_frame.listbox_insert("请检查无线网卡是否打开,设置是否正确")else:message_frame.listbox_insert("关闭WIFI失败!")else:if how == 1:message_frame.listbox_insert("WIFI已打开")else:message_frame.listbox_insert("WIFI已关闭")class ShowMessageFrame():"""will create a frame contanis a listbox and scrollbar"""def __init__(self):self.frame = Frame()self.message_ft = tkFont.Font(family="Arial", size=10)self.scrollbar = Scrollbar(self.frame, orient=VERTICAL)self.listbox = Listbox(self.frame, bg="grey", selectbackground="blue",selectmode="extended", font=self.message_ft, width=20)self.scrollbar.config(command=self.listbox.yview)self.scrollbar.pack(side=RIGHT, fill=Y)self.listbox.config(yscrollcommand=self.scrollbar.set)self.listbox.pack(side=LEFT, fill=BOTH, expand=1)self.listbox_insert("Welcome to WIFI!")def listbox_insert(self, args):self.listbox.insert(END, args)class MyMenu():"""Create the Menu for Window"""message_status = 1def __init__(self, root):self.menubar = Menu(root)self.optionmenu = Menu(self.menubar, tearoff=1)self.optionmenu.add_command(label='Show Message', command=lambda : self.show_messagebox(root))self.optionmenu.add_command(label='Hide Message', command=lambda : self.hide_messagebox(root))self.optionmenu.add_separator()self.optionmenu.add_command(label='Exit', command=lambda : close_window(root))self.menubar.add_cascade(label='Options', menu=self.optionmenu)self.helpmenu = Menu(self.menubar, tearoff=1)self.helpmenu.add_command(label='About', command=self.show_info)self.menubar.add_cascade(label='Help', menu=self.helpmenu)self.frame = ''def hide_messagebox(self, root):"""will hide the message listbox and scrollbar"""if self.message_status == 1:self.frame = root.grid_slaves(2,0)[0]root.grid_slaves(2,0)[0].grid_remove()self.__class__.message_status = 0def show_messagebox(self, root):if self.message_status == 0 and self.frame != '':#print root.grid_slaves(2,0)self.frame.grid(row=2, columnspan=2, pady=5, sticky=S+N+E+W)self.__class__.message_status = 1self.frame = ''def show_info(self):"""show the software info""" tkMessageBox.showinfo("About","""WIFI 热点助手------------------------------------------version: 1.0author: CullenEmail:  wangyiyan402@163.com------------------------------------------""" )class MyWindow():""" create the main window which include the image and two button(bounded the appropriate function"""def __init__(self):self.root = Tk()self.root.title("WIFI热点助手");self.root.resizable(0,0)#create menumy_menu = MyMenu(self.root)self.root.config(menu=my_menu.menubar)#font and imageself.button_ft = tkFont.Font(family="Arial", size=10, weight=tkFont.BOLD)self.image = Image.open("wifi.jpg")self.bm = ImageTk.PhotoImage(self.image)self.label = Label(self.root, image=self.bm)self.label.grid(row=0, columnspan=2)#create buttonself.open_button = Button(self.root, text="OPEN", font=self.button_ft, pady=10,width=10, borderwidth=2, bg="#F3E9CC", command=lambda : manage_wifi(1, message_frame))self.open_button.grid(row=1, column=0)self.close_button = Button(self.root, text="CLOSE", font=self.button_ft, pady=10,width=10, borderwidth=2, bg="#F3E9CC", command=lambda : manage_wifi(0, message_frame))self.close_button.grid(row=1, column=1)#create frame which include listbox and scrollbarmessage_frame = ShowMessageFrame()message_frame.frame.grid(row=2, columnspan=2, pady=5, sticky=S+N+E+W)#message_frame.frame.grid_forget()#prompt when user close the windowself.root.protocol('WM_DELETE_WINDOW', lambda : close_window(self.root))self.root.mainloop()if __name__ == '__main__':#main()my_window = MyWindow()

下面是运行后的结果:

点击open/close按钮会打开或关闭WIFI,并在下面的消息框内输出提示信息,右侧的滚动条可以进行上下移动,如下图所示:

菜单栏里的help会显示一些信息:

Option里的Hide Message会隐藏下面的消息框,而点击Show Message则又会重新显示出来:

而点击Exit子菜单和右上角的关闭图标,都会弹出对话框,让用户进行确认:

下面是源代码,运行环境为python2.7,不足之处请指出,谢谢!

点击打开链接

Python Tkinter实现的WIN7电脑端共享WIFI热点(二)相关推荐

  1. java windows wifi_[转] win7 电脑无线网变身WiFi热点

    酒店里没有 wifi ,手机无法上网,在网上找到一篇利用win7 电脑无线网变身WiFi热点的文章,试过可行. 将win7电脑变身WiFi热点,让手机.笔记本共享上网 用win7建立无线局域网,可以共 ...

  2. WIN7电脑如何共享WiFi

    步骤 1.设置WiFi,运行WIN+R–>cmd netsh wlan set hostednetwork mode=allow ssid=name key=password 2.电脑右下角,网 ...

  3. win7计算机怎样共享的打印机,两台win7电脑如何共享打印机

    操作系统:win7 64位旗舰版 两台win7电脑如何共享打印机?下面就一起来了解一下. 1.取消禁用Guest用户:因为别人要访问安装打印机的按个电脑就是以guest账户访问的.右击计算机,选择管理 ...

  4. 计算机双网口怎么共享网络,win7电脑怎么共享上网 两台电脑共享上网操作方法...

    电脑共享上网指的是多台设备通过共享网络资源,进行互联网访问的方式,在生活当中我们通常会碰到只有一根网线想让两台电脑或者多台电脑同时上网,那么win7电脑怎么共享上网呢?今天为大家分享两台电脑共享上网的 ...

  5. PC端通过WiFi热点共享代理

    以v2ray为例: 电脑开启共享wifi后,打开电脑的代理设置,可以看到端口为10810,然后运行ipconfig,查看本地连接的ip地址,手机连接到电脑上的热点后,设置手动代理,ip为电脑ip,端口 ...

  6. win7系统用笔记本共享wifi热点 让手机免费上网

    之前一直在用这个方法把自己的笔记本变成一个wifi热点,让手机也可以直接连wifi上网,节省网费和路由器购买费. 其实就是开启了windows 7的隐藏功能:虚拟WiFi和SoftAP(即虚拟无线AP ...

  7. 『教程』笔记本win7下自建Wifi热点–便于手机Wifi上网 (转 )

    说是教程,我也是从安致论坛上学来的,觉得还不错,于是再分享一次吧. 首先,以管理员身份运行命令提示符(用快捷键WIN+R调出运行然后输入CMD打开命令提示符的非是管理员权限),右击"命令提示 ...

  8. 笔记本win10宽带共享wifi热点教程

    win10宽带共享wifi热点教程 在校园内用电脑宽带拔号可能不能共享点,但此教程可供参考. 链接: win10宽带共享wifi热点教程.

  9. 怎么在Win7系统中开启Wifi热点

    怎么在Win7系统中开启Wifi热点 步骤 1.在开始菜单中点击"运行"或者是按下键盘的"win+R"组合键,然后输入"cmd"回车. 2. ...

最新文章

  1. asp.net数据格式的Format-- DataFormatString
  2. 非空约束对数据更新的影响
  3. 批量移动某目录下某类型的文件到指定的目录下
  4. 《大数据》第1期“专题”——大数据机器学习系统研究进展(下)
  5. 华为鸿蒙系统深度体验报告,堪比苹果IOS的存在!
  6. User breakpoint called from code at 0x771064f4
  7. 身份证号有效性检验代码 (python)
  8. Hibernate之一对一映射
  9. sqlyog怎么查找表_sqlyog各种搜索方法
  10. 绕过tp路由器管理密码_TP-Link路由器管理员密码多少 TP-Link路由器管理员密码介绍【详解】...
  11. 狂神说-Spring学习总结
  12. SQLServer 大容量导入导致死锁和系统变慢问题
  13. attrib批量显示文件夹_[attrib命令隐藏文件夹]Attrib命令,可以让文件夹彻底的隐藏起来(转载)...
  14. 基于Flink的JDBC插入Nested结构数据到Clickhouse
  15. 科学计算机感叹号,电脑网络黄三角感叹号怎么解决
  16. React 中constructor 作用
  17. 泛型在Android中的应用
  18. nas网络存储服务器性能要求,NAS系统的优缺点全面介绍
  19. tf.keras.layers.BatchNormalization、tf.keras.layer.LayerNormalization函数
  20. 树莓派控制Dobot遇到的问题

热门文章

  1. android gps无法定位,解决GPS无法定位问题
  2. WL2803E25-5/TR超低压差 低压静态电流 高PSRR CMOS LDO
  3. 如何用个人电脑利用ipv6搭建网站
  4. 世上无难事,只怕有心人!
  5. Photoshop零基入门软件简单介绍
  6. win8服务器设置虚拟机,win8系统怎么安装虚拟机 win8系统安装虚拟机的详细图文教程...
  7. 2020双十一成交额 双11各电商平台销售额数据
  8. spotlight安装使用
  9. 单片机数字定时闹钟设计c语言,电子设计 基于51单片机的定时闹钟设计.doc
  10. HanLP极致简繁转换详细讲解 1