gpt4 book ai didi

python - TKinter:如何设置子窗口的窗口图标(Toplevel)

转载 作者:行者123 更新时间:2023-11-28 17:36:21 27 4
gpt4 key购买 nike

我正在尝试将一个窗口图标添加到主窗口的子窗口中,该窗口内置于 TKinter 中。为了便携性(又名不丢失文件),我从 base64 编码的 gif 中设置了主窗口图标作为变量。我一直无法为子窗口复制它。

from Tkinter import *

ICON = """
R0lGODlhMgAyAPcAAAAAAAAAMwAAZgAAmQAAzAAA/wArAAArMwArZgArmQArzAAr/wBVAABVMwBV
ZgBVmQBVzABV/wCAAACAMwCAZgCAmQCAzACA/wCqAACqMwCqZgCqmQCqzACq/wDVAADVMwDVZgDV
mQDVzADV/wD/AAD/MwD/ZgD/mQD/zAD//zMAADMAMzMAZjMAmTMAzDMA/zMrADMrMzMrZjMrmTMr
zDMr/zNVADNVMzNVZjNVmTNVzDNV/zOAADOAMzOAZjOAmTOAzDOA/zOqADOqMzOqZjOqmTOqzDOq
/zPVADPVMzPVZjPVmTPVzDPV/zP/ADP/MzP/ZjP/mTP/zDP//2YAAGYAM2YAZmYAmWYAzGYA/2Yr
AGYrM2YrZmYrmWYrzGYr/2ZVAGZVM2ZVZmZVmWZVzGZV/2aAAGaAM2aAZmaAmWaAzGaA/2aqAGaq
M2aqZmaqmWaqzGaq/2bVAGbVM2bVZmbVmWbVzGbV/2b/AGb/M2b/Zmb/mWb/zGb//5kAAJkAM5kA
ZpkAmZkAzJkA/5krAJkrM5krZpkrmZkrzJkr/5lVAJlVM5lVZplVmZlVzJlV/5mAAJmAM5mAZpmA
mZmAzJmA/5mqAJmqM5mqZpmqmZmqzJmq/5nVAJnVM5nVZpnVmZnVzJnV/5n/AJn/M5n/Zpn/mZn/
zJn//8wAAMwAM8wAZswAmcwAzMwA/8wrAMwrM8wrZswrmcwrzMwr/8xVAMxVM8xVZsxVmcxVzMxV
/8yAAMyAM8yAZsyAmcyAzMyA/8yqAMyqM8yqZsyqmcyqzMyq/8zVAMzVM8zVZszVmczVzMzV/8z/
AMz/M8z/Zsz/mcz/zMz///8AAP8AM/8AZv8Amf8AzP8A//8rAP8rM/8rZv8rmf8rzP8r//9VAP9V
M/9VZv9Vmf9VzP9V//+AAP+AM/+AZv+Amf+AzP+A//+qAP+qM/+qZv+qmf+qzP+q///VAP/VM//V
Zv/Vmf/VzP/V////AP//M///Zv//mf//zP///wAAAAAAAAAAAAAAACH5BAEAAPwALAAAAAAyADIA
AAj/APcJHEiwoMGDCBMqXCjQnsOHECEynIgQIjx7FzNi3HjRIcWPHC0+7LixpL2PCk2GXNmx5UaU
BkW6NDlzpkeY+xxq1MmTZU+XF2GWrNnz50ijJykO5Um0KdKgDI+qJEm1KM2fC3cCZYrU59KbFb1O
NVr1a8aEY30SlWqTZNKYK6+a5eqU48GiO0sC2Mu3I9++XUkWXFq15d+9Og8DeMqVoE28DhX7PdzW
KkGyXDEqTnyYcciBmOVKjkyZLeSGleVGtHp0reB9qZ1qLJyWaMO5X+Xm3ToXHmrPdWkHLnob91rC
rYFjFKhVeVfIuV+b3shXeXN71Zv+zv3X9fS/05MyoIbX2fvQ8mSZQyedXTn63LedbjaOvTPj7Y/r
g8e9+XrH+JhdNN9XA96nXnQP9dfTfP6BlRN9Ag6o2GLIDXWZeQlOOOFwPA0GIXsaIvahQebNFOJ0
j91VImsyKYdWWcfNpptpKXmFYWxSZYXijhXWNNGM9NXWoVJBxjgXTCsWOSSS0CXpEk6X2eicb1DC
hduVVSIEY5MOZhnWli95KaaXAQEAOw==
"""

class ChildWindow(Toplevel):
def __init__(self, callingFrame):
self.parent = callingFrame
Toplevel.__init__(self)
self.title("Child")
self.initUI()

def initUI(self):

#this doesn't work in this class, unlike the first class where it does work.
global ICON
self.icon = PhotoImage(data=ICON)
self.call('wm', 'iconphoto', self.parent._w, self.icon)

btn = Button(self, text="Close", command=self.destroy)
btn.pack()


class ParentWindow(object):

def __init__(self, parent):
self.parent = parent
self.parent.title("Parent")
self.frame = Frame(parent)
self.initUI()

def initUI(self):
global ICON
self.icon = PhotoImage(data=ICON)
self.parent.call('wm', 'iconphoto', self.parent._w, self.icon)

btn = Button(self.parent, text="Child", command=self.opennew)
btn.pack()

def opennew(self):
newwin = ChildWindow(self)

def main():
root = Tk()
win = ParentWindow(root)
root.geometry()
root.mainloop()


if __name__ == '__main__':
main()

最佳答案

替换:

self.call('wm', 'iconphoto', self.parent._w, self.icon)

与:

self.tk.call('wm', 'iconphoto', self._w, self.icon)

关于python - TKinter:如何设置子窗口的窗口图标(Toplevel),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30198805/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com