我的输出显示 tkinter 小部件错误和按钮错误,而不显示按钮

问题描述

    from tkinter import Tk,Button,Label,Scrollbar,ListBox,StringVar,Entry,W,E,N,S,END

    from tkinter import ttk
    from tkinter import messageBox
    #  creates application window
    root = Tk()
    root.title("My Todo List App")  # adds title to app window
    root.configure(background="light green")   # adds background colour to application window
    root.geometry("550x500")     # sets a size for application window
    root.resizable(width=False,height=False)    # prevents further resizing

   # Create labels and entry widgets

   title_label = ttk.Label(root,text="Title",background="light green",font=("TkDefaultFont",16))
   title_label.grid(row=0,column=0,sticky=W)
   title_text = StringVar()
   title_entry = ttk.Entry(root,width=25,textvariable=title_text)
   title_entry.grid(row=0,column=1,sticky=W)

   # Add a button to insert inputs into database

   add_btn = Button(root,text="Add Task",bg="blue",fg="white",font="helvetica 1- bold",command="")
   add_btn.grid(row=0,column=2,sticky=W)



   root.mainloop()      # runs the application until exit

我的错误

C:\Users\tkurd\AppData\Local\Programs\Python\python39\python.exe C:/Users/tkurd/Desktop/todolist/todo.py
  
Traceback (most recent call last):

  File "C:\Users\tkurd\Desktop\todolist\todo.py",line 22,in <module>
    add_btn = Button(root,command="")

 File "C:\Users\tkurd\AppData\Local\Programs\Python\python39\lib\tkinter\__init__.py",line 2650,in __init__
    Widget.__init__(self,master,'button',cnf,kw)

 File "C:\Users\tkurd\AppData\Local\Programs\Python\python39\lib\tkinter\__init__.py",line 2572,in __init__
    self.tk.call(
        _tkinter.TclError: expected integer but got "1-"

 Process finished with exit code 1

解决方法

在 Tkinter 中指定字体时,我们不包括连字符 (-)。仅使用空格,文本应仅为 a) 字体大小 b) 字体名称 c) 粗体、斜体或下划线。

因此将第 23 行替换为: add_btn = Button(root,text="Add Task",bg="blue",fg="white",font="helvetica 1 bold",command="")

注意:按钮的文字可能看起来消失了,但只是字体大小为1。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...