【问题标题】:What is optionDB?什么是选项数据库?
【发布时间】:2020-12-11 01:58:27
【问题描述】:

我想在tkinter 中创建一个toplevel widget,但是当我运行程序时它给了我一个错误。回溯会将我引向 optionDB,表明它不在我的目录中——这是真的。我在哪里可以下载或找到optionDB,它到底是什么?我也搜索了网络,但我找不到一个好的答案。我希望有人可以帮助我。

可能有其他方法可以创建toplevel widget,但我也想知道 optionDB 是什么。对不起,我还是个初学者,还不够了解。

from tkinter import *
root = Tk()
root.option_readfile("optionDB")
root.title("Toplevel")

追溯:

_tkinter.TclError: couldn't open "optionDB": no such file or directory

【问题讨论】:

    标签: python python-3.x user-interface tkinter


    【解决方案1】:

    顾名思义,optionDB 存储所有选项,如字体等。并且通常按如下方式加载:似乎您没有文件或文件不在路径中。 现在你可以在路径中创建一个空文件,看看它是否移动得更远。

    Setting application-wide default fonts tkinter root window

    其他可用的选项相关方法

     |  option_add(self, pattern, value, priority=None)
     |      Set a VALUE (second parameter) for an option
     |      PATTERN (first parameter).
     |
     |      An optional third parameter gives the numeric priority
     |      (defaults to 80).
     |
     |  option_clear(self)
     |      Clear the option database.
     |
     |      It will be reloaded if option_add is called.
     |
     |  option_get(self, name, className)
     |      Return the value for an option NAME for this widget
     |      with CLASSNAME.
     |
     |      Values with higher priority override lower values.
     |
     |  option_readfile(self, fileName, priority=None)
     |      Read file FILENAME into the option database.
     |
     |      An optional second parameter gives the numeric
     |      priority.
    

    【讨论】:

    • 天哪!非常感谢。我实际上只是创建了一个 optionDB.txt 文件;将我的代码更改为 root.option_readfile('optionDB.txt'),它起作用了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-09
    • 2011-05-01
    • 2012-02-02
    • 1970-01-01
    • 1970-01-01
    • 2012-06-13
    相关资源
    最近更新 更多