小编Rqo*_*mey的帖子

单击"确定"后,Tkinter TkMessageBox未关闭

我用Python创建了一个脚本,它在给定的事件中通知我.我使用以下函数来生成警告窗口:

def window_warn():
    '''
    This function will throw up a window with some text
    '''
    #These two lines get rid of tk root window
    root = Tkinter.Tk()
    root.withdraw()
    #tkMessageBox.deiconify() 
    TkMessageBox.showwarning("New Case", "You have a new case\n Please restart pycheck")
    return
Run Code Online (Sandbox Code Playgroud)

窗口绘制正常,但是当我单击确定时,窗口会在按下按钮的情况下保持原位.我正在使用xfce.无论如何在点击确定后让窗口关闭?

评论表明这可能与周围的代码有关,所以为了完整性:

print "Just started newcase check"
while True:
    if "Uncommitted" in webpage:
        print "oh look, 'Uncommitted' is in the url returned from the last function"
        #If this hits we call a notification window
        window_warn()
        print "sleeping"
        time.sleep(10)

        webpage = …
Run Code Online (Sandbox Code Playgroud)

python tkinter xfce python-2.7

6
推荐指数
1
解决办法
3973
查看次数

Python-将变量参数传递给subprocess.call的最佳方法

我试图使用python脚本多次调用外部命令,每次使用不同的变量.

我看到有建议使用subprocess.call来做到这一点,但是我找到的所有文档都没有解释如何传递这个函数变量(例如从列表中).

我已经尝试了许多不同的格式,我认为替换会是最好的,但似乎函数不会接受变量.我想要的代码是:

#!/usr/bin/python
domain_list             = ["google.com", "google.ie"]

from subprocess import call

for x in domain_list:
    print x
    cmd_list       = ['dig', '+short', '%s'] %x
    call(cmd_list, shell=True)
Run Code Online (Sandbox Code Playgroud)

这失败了:

Traceback (most recent call last):
File "./dnscheck.py", line 16, in <module>
cmd_list    = ['dig', '+short', '%s'] %arg
TypeError: unsupported operand type(s) for %: 'list' and 'str'
Run Code Online (Sandbox Code Playgroud)

我真的希望能够通过一堆不同的域(在列表中定义)来挖掘和接收这些域的IP.

我刚开始使用python,对不起,如果这是非常基本的!

python function

2
推荐指数
1
解决办法
2668
查看次数

标签 统计

python ×2

function ×1

python-2.7 ×1

tkinter ×1

xfce ×1