小编J.W*_*ong的帖子

模式匹配 Tkinter 子小部件 (winfo_children) 以确定类型

我正在尝试自动清除Entry父小部件中的所有小部件。

import Tkinter
import re
root=Tkinter.Tk()

E1=Tkinter.Entry(root)
E1.pack()

E2=Tkinter.Entry(root)
E2.pack()

L1=Tkinter.Label(root,text='Label1')
L1.pack()
Run Code Online (Sandbox Code Playgroud)

我遇到了 3 个问题

  1. 虽然我可以找出子部件类型,但我似乎无法在模式匹配中使用它。打印出wlist[0]以下与shell输出不同?

例如:

import Tkinter
import re
root=Tkinter.Tk()

E1=Tkinter.Entry(root)
E1.pack()

E2=Tkinter.Entry(root)
E2.pack()

L1=Tkinter.Label(root,text='Label1')
L1.pack()
Run Code Online (Sandbox Code Playgroud)
  1. 我想由于上面的打印输出和 shell 输出之间的差异,我的模式匹配不能工作?

例如

>> re.search(r'Entry',wlist[0])
    << No output >>
Run Code Online (Sandbox Code Playgroud)
  1. 假设一个人能够通过模式匹配确定一个子部件确实是一个Entry部件,你将如何让部件对象本身执行delete方法调用?

例如:

## Assuming I have a function to to clear the entry
## How would I pass the object from the pattern match in #2 to this function?
def clear_entry(objEntry):
    objEntry.delete(0,Tkinter.END)
Run Code Online (Sandbox Code Playgroud)

python tkinter widget pattern-matching

4
推荐指数
2
解决办法
8967
查看次数

标签 统计

pattern-matching ×1

python ×1

tkinter ×1

widget ×1