Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用.config时出现巨大错误消息_Python_Python 3.x_Tkinter - Fatal编程技术网

Python 使用.config时出现巨大错误消息

Python 使用.config时出现巨大错误消息,python,python-3.x,tkinter,Python,Python 3.x,Tkinter,我正在努力学习tkinter,正在做一个计算器 我正在设置按钮,现在尝试使用以下方法更改其中一个按钮的大小: Button_back = ttk.Button(Frame1, text='Back', command=printhi) #printhi is temporary. Button_back.grid(column=0, row=0) Button_back.config( height = 25, width = 25 ) 当我尝试运行它时,错误消息是: >Tracebac

我正在努力学习tkinter,正在做一个计算器

我正在设置按钮,现在尝试使用以下方法更改其中一个按钮的大小:

Button_back = ttk.Button(Frame1, text='Back', command=printhi) #printhi is temporary.
Button_back.grid(column=0, row=0)
Button_back.config( height = 25, width = 25 )
当我尝试运行它时,错误消息是:

>Traceback (most recent call last):   File "C:\Users\Luuk\Python
>PGMs\tkinter\2-1 - Calculator.py", line 75, in <module>
>Button_back.config( Height = 25, width = 25 )

>File "C:\Program Files (x86)\Python34\lib\tkinter\__init__.py", line 1270, in configure

>return self._configure('configure', cnf, kw)   File "C:\Program Files (x86)\Python34\lib\tkinter\__init__.py", line 1261, in
> _configure
>self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))

> _tkinter.TclError: unknown option "-height"
>回溯(最后一次调用):文件“C:\Users\Luuk\Python”
>PGMs\tkinter\2-1-Calculator.py“,第75行,在
>Button_back.config(高度=25,宽度=25)
>文件“C:\Program Files(x86)\Python34\lib\tkinter\\uuuu init\uuuu.py”,第1270行,在配置中
>返回self.\u configure('configure',cnf,kw)文件“C:\Program Files(x86)\Python34\lib\tkinter\\uuuuuu init\uuuuu.py”,第1261行,在
>_配置
>self.tk.call(_flatten((self._w,cmd))+self._选项(cnf))
>\u tkinter.TclError:未知选项“-高度”

我不知道我做错了什么,根据每个网页,这是正确处理宽度和高度的方法。

按钮没有“高度”这个词,只有宽度。。。(可能还有其他事情,但这是我现在肯定知道的)

在另一个半小时的搜索后发现:


你的答案有一半是对的……但是
Tkinter
按钮有一个高度选项,而不是
ttk
按钮。如果你绝对需要高度选项,你仍然可以使用一个普通的Tkinter按钮,它不会那么漂亮。此外,如果您再次使用此绑定,可以通过打印
widget.config()
来打印widget选项字典

import tkinter as tk
import ttk


root = tk.Tk()

tk_button = tk.Button(root, text='tkinter button')
ttk_button = ttk.Button(root, text='ttk button')

for key in tk_button.config().iterkeys():
    print('tkinter: ' + key)

for key in ttk_button.config().iterkeys():
    print('ttk: ' + key)

tk_button.pack()
ttk_button.pack()


root.mainloop()