【发布时间】:2021-04-03 03:42:42
【问题描述】:
使用此答案中的代码:Get list of Toplevels on Tkinter:
'''
List all objects in play next song
https://stackoverflow.com/questions/60978666/get-list-of-toplevels-on-tkinter
'''
LAST_TIME=0.0
THING_COUNT=0
def toplevels(ventana):
global LAST_TIME, THING_COUNT
now = time.time()
if not int(now) == int(LAST_TIME):
if THING_COUNT > 0:
print('Number of things:', THING_COUNT)
THING_COUNT = 0
print('\n============= toplevels() called at:', t(now),'=============')
LAST_TIME = now
for k, v in ventana.children.items():
if isinstance(v, tk.Toplevel):
print('Toplevel:', k, v)
else:
print(' other:', k, v)
toplevels(v)
THING_COUNT += 1
我这样称呼它:
toplevels(root)
输出是这样的:
Number of things: 42
============= toplevels() called at: Dec 24 2020 12:03:27 =============
Toplevel: 140109521792176 .140109521792176
other: 140109520829184 .140109521792176.140109520829184
other: 140109520830264 .140109521792176.140109520829184.140109520830264
other: 140109520859360 .140109521792176.140109520829184.140109520859360
other: 140109520829472 .140109521792176.140109520829184.140109520829472
other: 140109521432304 .140109521792176.140109521432304
other: 140109520827600 .140109521792176.140109521432304.140109520827600
other: 140109520828032 .140109521792176.140109521432304.140109520827600.140109520828032
other: 140109520827888 .140109521792176.140109521432304.140109520827600.140109520827888
other: 140109520828896 .140109521792176.140109521432304.140109520827600.140109520828896
other: 140109520828176 .140109521792176.140109521432304.140109520827600.140109520828176
other: 140109520828608 .140109521792176.140109521432304.140109520827600.140109520828608
other: 140109520828392 .140109521792176.140109521432304.140109520827600.140109520828392
other: 140109520767024 .140109521792176.140109521432304.140109520767024
other: 140109520827384 .140109521792176.140109521432304.140109520767024.140109520827384
other: 140109520767096 .140109521792176.140109521432304.140109520767024.140109520767096
other: 140109520827096 .140109521792176.140109521432304.140109520767024.140109520827096
Toplevel: 140109520827168 .140109520827168
other: 140109521621360 .140109520827168.140109521621360
other: 140109521623016 .140109520827168.140109521621360.140109521623016
other: 140109521621576 .140109520827168.140109521621360.140109521621576
other: 140109521623160 .140109520827168.140109521621360.140109521623160
other: 140109521623376 .140109520827168.140109521621360.140109521623376
other: 140109521622152 .140109520827168.140109521621360.140109521622152
other: 140109521622728 .140109520827168.140109521621360.140109521622728
other: 140109521623232 .140109520827168.140109521621360.140109521623232
other: 140109521621936 .140109520827168.140109521621360.140109521621936
other: 140109521622800 .140109520827168.140109521621360.140109521622800
other: 140109521622944 .140109520827168.140109521621360.140109521622944
other: 140109521623448 .140109520827168.140109521621360.140109521623448
other: 140109521623520 .140109520827168.140109521623520
other: 140109521624888 .140109520827168.140109521623520.140109521624888
other: 140109521624024 .140109520827168.140109521623520.140109521624024
other: 140109521623664 .140109520827168.140109521623520.140109521623664
other: 140109396840528 .140109520827168.140109521623520.140109396840528
other: 140109521624456 .140109520827168.140109521623520.140109521624456
other: 140109521624240 .140109520827168.140109521623520.140109521624240
other: 140109521624672 .140109520827168.140109521623520.140109521624672
other: 140109396840744 .140109520827168.140109521623520.140109396840744
other: 140109396840960 .140109520827168.140109396840960
other: 140109396841176 .140109520827168.140109396840960.140109396841176
other: 140109396841392 .140109520827168.140109396840960.140109396841392
它正确地显示了两个顶层。首先是音乐库树形视图。 Second 当前正在播放四帧歌曲:
- 专辑封面图片
- 当前播放歌曲的详细信息(艺术家、专辑、曲目等)
- 按钮(关闭、暂停/播放、随机播放、下一个、上一个等)
- 年表树状视图(最近播放、当前播放、下一个播放)
如何转换机器语言参考:
other: 140109521624240 .140109520827168.140109521623520.140109521624240
转化为人类可读的格式,例如:
- 这是一个 x 宽、y 高的窗口,安装在桌面的 x,y 处,name="self.play_top"
- 这是 nsew 的框架,带有时髦的浮雕,name="playfrm"
- 这是一个默认字体的标签,大小为 12 磅,包含“此文本”,文本变量="self.current_song_name"
- 这是一个按钮,text="✘ Close", padx=2, pady=2, foreground="#0000000", background="#ffffff", internal name="blah blah"
我需要创建一个函数,以人类可读的格式呈现信息,并允许更改颜色、字体大小(hDPI 监视器)、主题等。然后将这些更改应用于另一个使用 .configure() 方法的函数。我还计划使用字典并存储在 pickle 配置文件中以供以后重新应用。
【问题讨论】:
-
当您使用
print(v)时,您将实际对象转换为引用字符串。只需保存v对象即可。 -
@Novel 当你说“简单保存”时,这意味着将
print(v)更改为print(save(v)),但我认为你不是那个意思。 -
好吧,我不知道你想对这些对象做什么,所以“保存”是指做任何你想做的事情。例如,如果你想打印出宽度,你可以
print(v.winfo_width())。 -
@Novel 这就像一个魅力!现在我必须弄清楚如何遍历对象具有 bseides
winfo_width()的所有属性。接下来我必须开始使用if子句选择要打印的属性。 -
@Novel 感谢您的帮助,我发布了一个达到预期最终结果的答案。中间步骤(列出所有属性等)的答案会更长,因为诊断输出有数千行。