python tkinter模块 创建窗口V1.2
先上图

代码如下
#-*-coding:utf-8-*-
import os
from tkinter import * root=Tk()
root.title('执行窗口') """
V1.2 """
def add(a,b):
a=int(a)
b=int(b)
sum=eval('a+b') #执行表达式
print('a+b=',sum) return sum #调用其他函数fun(asg1,asg2)
def go_func():
#第一个参数,调用函数,第2个参数,函数参数
func = n51.get()
asgs = n52.get()
func = eval(func) #转为函数
#print(type(func))
#无参数
if len(asgs) == 0:
func()
else:
#多参数j,分割
asg=asgs.split(',')
func(*asg) #--------------------------------------
#清空文本框内容
def clear():
text.delete('1.0','end') #执行
def show():
print('hello')
text.insert('1.0', "hello\n") #文本信息
def insert_text(msg):
text.insert(INSERT,'%s'%msg) def get_app_deviceid():
print('请先检查是否连接了设备,是否启动了开发者选项,是否开启了adb调试....')
#查看连接设备
out=os.popen('adb devices').read()
patter= re.compile(r"[a-zA-Z0-9]+")
device_list=patter.findall(out)
#print(device_list)
print('设备连接信息:--------------------------------------\n',out) #调取text
insert_text(out) #存放设备号
deviceid=[]
#提取设备号,存放到deviceid中,
if 'device' in device_list:
#print('设备号:',deviceid)
#多个设备,
n=4
while len(device_list)>n:
deviceid.append(device_list[n])
n=n+2
print('设备号:',deviceid)
else:
print('无此设备,请检查是否连接设备。')
return out #执行cmd命令
def execute_cmd(cmd='adb devices'):
cmd= e1.get()
print(cmd)
out = os.popen(cmd).read()
print(out)
return out def get_text():
# 获取entry输入的文字
str2=""
str2=e1.get() # 在光标处插入文字
text.insert("insert", str2) #-grid----------------------------------------------------------------------- #label控件
Label(root,text="输入命令:").grid(row=0,column=0,sticky=E) #靠右
Label(root,text="本地目录:").grid(row=1,column=0,sticky=E) #靠右
Label(root, text='手机目录').grid(row=2,column=0,sticky=E) #靠左 Label(root, text='显示结果',width=15).grid(row=3,column=1,sticky=W) #靠左 #输入控件
e1=Entry(root,width=30)
e1.grid(row=0,column=1,padx=5,pady=5)
e2=Entry(root,width=30)
e2.grid(row=1,column=1,padx=5,pady=5)
e3=Entry(root,width=30)
e3.grid(row=2,column=1,padx=5,pady=5) #命令控件
#b1=Button(root,text="点击看看吧",command=show,height=1,width=15,fg='blue').grid(row=2,column=1)
#Label(root, text='显示结果', width=15, height=1).grid(row=2,column=1,sticky=W) #靠左
#grid(row=1,column=2),row,行,从0开始,column列从0开始;
b1=Button(root,text="执行命令",command=get_text,height=1,width=15,fg='blue').grid(row=0,column=2,padx=5, pady=5)
b2=Button(root,text="安装包",command=show,height=1,width=15,fg='blue').grid(row=1,column=2,padx=5, pady=5) b3=Button(root,text="查看设备",command=get_app_deviceid,height=1,width=15,fg='blue').grid(row=4,column=0,padx=5, pady=5)
b4=Button(root,text="清空",command=clear,height=1,width=15,fg='black').grid(row=4,column=2,padx=5, pady=5) #显示结果,text控件
text = Text(root, width=30, font =('Verdana',10),fg='blue')
text.grid(row=4,column=1,rowspan=3) #调用函数
Label(root, text='调用函数').grid(row=8,column=0)
Label(root, text='输入函数名').grid(row=8,column=1)
Label(root, text='输入参数').grid(row=8,column=2) #调用函数
b5= Button(root,text = "加法",command = go_func,width = 15).grid(row = 9,column = 0,padx=5, pady=5)
#输入函数名
var1 = StringVar()
n51 = Entry(root,width = 30,textvariable = var1)
var1.set("add")
n51.grid(row = 9,column = 1) #输入函数参数
var2 = StringVar()
n52 = Entry(root,width = 30,textvariable = var2)
var2.set("a,b")
n52.grid(row = 9,column = 2) root.mainloop()
python tkinter模块 创建窗口V1.2的更多相关文章
- Python tkinter模块弹出窗口及传值回到主窗口操作详解
这篇文章主要介绍了Python tkinter模块弹出窗口及传值回到主窗口操作,结合实例形式分析了Python使用tkinter模块实现的弹出窗口及参数传递相关操作技巧,需要的朋友可以参考下 本文实例 ...
- python3中 tkinter模块创建window窗体、添加按钮、事务处理、创建菜单等的使用
开始接触桌面图形界面编程,你可以到安装路径 \lib\tkinter 打开__init__.py 文件了解tkinter 1 tkinter 模块创建窗体,代码如下截图: 运行结果,如有右图显 ...
- python - Tkinter 模块 - python 自带的gui模块
Tkinter模块("Tk 接口")是Python的标准Tk GUI工具包的接口,位Python的内置模块,直接import tkinter即可使用. 1.创建窗口 from Tk ...
- Python Tkinter模块 Grid(grid)布局管理器参数详解
在使用Tkinter模块编写图像界面时,经常用到pack()和grid()进行布局管理,pack()参数较少,使用方便,是最简单的布局,但是当控件数量较多时,可能需要使用grid()进行布局(不要在同 ...
- 利用TKinter模块创建GUI窗口
# -*- coding: utf-8 -*- from Tkinter import * root = Tk() # 80x80代表了初始化时主窗口的大小,0,0代表了初始化时窗口所在的位置 ...
- Python tkinter模块和参数
转自:https://www.cnblogs.com/aland-1415/p/6849193.html 1.使用tkinter.Tk() 生成主窗口(root=tkinter.Tk()):root. ...
- python XlsxWriter模块创建aexcel表格
https://blog.csdn.net/qq_41030861/article/details/82148777 安装使用pip install XlsxWriter来安装,Xlsxwriter用 ...
- python tkinter模块小工具界面
代码 #-*-coding:utf-8-*- import os from tkinter import * root=Tk() root.title('小工具') #清空文本框内容 def clea ...
- python TKinter的主窗口运行程序完毕后,怎么让其自动关闭
如题: 在pycharm 调试Tkinter程序的时候,关闭右上角的X 实际上并未退出进程,长期以往 再大的内存也会被耗尽. 一般就是下面的代码: """ from tk ...
随机推荐
- Git实战(三)环境搭建
上次的博文中.我们介绍了一下关于Git作为版本号控制工具的基本原理,接下来我们来搭建一个主要的Git环境(因为我使用的是Windows系统.所以重点側重在这方面). Git安装 Git的安装很easy ...
- GPU 编程入门到精通(三)之 第一个 GPU 程序
博主因为工作其中的须要.開始学习 GPU 上面的编程,主要涉及到的是基于 GPU 的深度学习方面的知识,鉴于之前没有接触过 GPU 编程,因此在这里特地学习一下 GPU 上面的编程.有志同道合的小伙伴 ...
- 不能不说的C#特性-表达式树
不能不说的C#特性-表达式树 2008-09-18 00:00 by 横刀天笑, 17112 阅读, 14 评论, 收藏, 编辑 最近发生了很多很多事情,频繁的搬家.工作上的事情也挺多的,所以博客更新 ...
- 高效开发之SASS篇 灵异留白事件——图片下方无故留白 你会用::before、::after吗 link 与 @import之对比 学习前端前必知的——HTTP协议详解 深入了解——CSS3新增属性 菜鸟进阶——grunt $(#form :input)与$(#form input)的区别
高效开发之SASS篇 作为通往前端大神之路的普通的一只学鸟,最近接触了一样稍微高逼格一点的神器,特与大家分享~ 他是谁? 作为前端开发人员,你肯定对css很熟悉,但是你知道css可以自定义吗?大家 ...
- LeetCode 249. Group Shifted Strings (群组移位字符串)$
Given a string, we can "shift" each of its letter to its successive letter, for example: & ...
- LeetCode 237. Delete Node in a Linked List (在链表中删除一个点)
Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...
- Redux 源码解读--createStore,js
一.依赖:$$observable.ActionTypes.isPlainObject 二.接下来看到直接 export default 一个 createStore 函数,下面根据代码以及注释来分析 ...
- android binder 基础实例及解析(一)【转】
本文转载自:http://blog.csdn.net/newchenxf/article/details/49359283#insertcode 原文网址(转载请注明出处): http://blog. ...
- codeforces 939F 单调队列优化dp
F. Cutlet time limit per test 4 seconds memory limit per test 256 megabytes input standard input out ...
- 【WIP】Bootstrap modal
创建: 2017/09/28 更新: 2017/10/14 标题加上[WIP]