rf+python实现调用本地弹框获取输入的文本
作者:互联网
rf的testcase文件:
*** Settings ***
Library ../Methodlibrary/keywords.py
*** Test Cases ***
弹框输入文本
${orderid} getinputstr please input orderId
log ${orderid}
keywords.py文件(python2版本):
# -*- coding: utf-8 -*-
from time import time
from Tkinter import *
inputstr = ''
def getinputstr(title):
"""
设置弹出框的标题,得到输入框内容,不允许为空值。目前不允许输入中文,可以粘贴中文,rf中标题不能直接用中文。
"""
def putstr():
global inputstr
inputstr = str(var.get().strip().encode('utf-8'))
root.destroy()
if inputstr is not '':
pass
else:
inputstr = getinputstr(title)
def inputclear():
var.set('')
inputstr = ''
root = Tk(className=title) # 弹出框框名
# screenwidth, screenheight = root.maxsize()
width = 300
height = 80
# size = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2) # 居中显示
size = '%dx%d' % (width, height)
root.geometry(size) # 设置弹出框的大小 w x h
var = StringVar() # 这即是输入框中的内容
var.set('') # 通过var.get()/var.set() 来 获取/设置var的值
entry1 = Entry(root, textvariable=var) # 设置"文本变量"为var
entry1.pack() # 将entry"打上去"
entry1.focus_set() # 显示光标
btn1 = Button(root, text='Input', command=putstr) # 按下此按钮(Input), 触发inputint函数
btn2 = Button(root, text='Clear', command=inputclear) # 按下此按钮(Clear), 触发inputclear函数
# 按钮定位
btn2.pack(side='right')
btn1.pack(side='right')
# 上述完成之后, 开始真正弹出弹出框
root.mainloop()
return inputstr
标签:set,python,弹框,width,rf,var,inputstr,height,root 来源: https://blog.csdn.net/weixin_42622119/article/details/89715355