此代码来自另一个有疑问的用户,但我想进一步介绍。按下此按钮将仅打印回控制台。如果我想将此答案打印到文本框中怎么办,我将如何编写该代码?
import tkinter
from tkinter import Button
top = tkinter.Tk()
def callback():
print ("click!")
button = Button(top, text="OK", command=callback)
top.mainloop()
答案 0 :(得分:0)
import tkinter as tk
from tkinter import *
from tkinter import Label,Text
top = tk.Tk()
top.title("My App")
top.geometry("600x500")
def what_is_your_name():
name1 = ('Hugh')
name2 = (entry1.get())
return name1 + name2
def name_display():
greeting = what_is_your_name()
#-----textbox----
textbox_name=tk.Text(master=top, height= 10, width=30)
textbox_name.grid(column=2, row=5)
textbox_name.insert(tk.END, greeting)
#------labels------
label1=tk.Label(text = "Enter your data here", font=("Helvetica", 10), fg="blue")
label1.grid(column=0, row=1)
#-----entry field-----
entry1=tk.Entry()
entry1.grid(column=0, row=0)
#-----button-----
button = tk.Button(text="Click Me", command=name_display)
button.grid(column = 0, row=3)
top.mainloop()