【问题标题】:Set a titlebar icon for a turtle window [closed]为乌龟窗口设置标题栏图标[关闭]
【发布时间】:2020-05-18 09:07:26
【问题描述】:

有没有办法为海龟模块设置标题栏图标?我想要这样的东西:

我想放一个标题栏图标,不知道怎么做。

【问题讨论】:

    标签: python python-turtle


    【解决方案1】:

    这似乎有效:

    import turtle
    import tkinter
    turtle.title('Hello Tux')
    img = tkinter.Image("photo", file="/usr/share/pixmaps/tuxpaint.png")
    turtle._Screen._root.iconphoto(True, img)
    

    你必须调用一些函数来强制创建根tkinter窗口,最明显的是设置标题。然后你可以访问标准的tkinter函数来设置图标。

    【讨论】:

    • 你的方法有效。谢谢!
    【解决方案2】:

    turtle 基于tkinter。深入研究turtle 的源代码会发现,为了达到你需要的底层tkinter 基础:

    import turtle
    
    root = turtle.Screen()._root
    

    现在这个root实际上是一个tkinterTk对象,它有iconbitmap方法:

    root.iconbitmap("path_to.ico")
    

    【讨论】:

      猜你喜欢
      • 2018-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-28
      • 1970-01-01
      • 2018-02-23
      • 2010-10-27
      • 1970-01-01
      相关资源
      最近更新 更多