首页 > 解决方案 > 当我运行此代码时,会出现一个没有按钮的空白 Tkinter 窗口

问题描述

from tkinter import *

root = Tk()

def printName(event):
    name = input("what is your name?")
    print("My name is" + name)


    printButton = Button(root,text = "Cliek Me")
    printButton.bind("<Button-1>",printNme)
    printButton.pack()

    root.mainloop()

标签: pythontkinter

解决方案


下面的代码应该可以解决您的问题。根据代码的要求填写引号内的空白。

from tkinter import *

root = Tk()


def printName():
    name = input("what is your name?")
    print("My name is" + "")

    printButton = Button(root, text="Cliek Me")
    printButton.bind("<Button-1>", "")
    printButton.pack()

    root.mainloop()
printName()
 

推荐阅读