简体   繁体   English

Python tkinter 按钮命令

[英]Python tkinter button command

I want to make an app that if you press a button it will print a letter in a textbox.我想制作一个应用程序,如果您按下按钮,它将在文本框中打印一个字母。 I created the button:我创建了按钮:

Button(window, text="Button1", width=5,command = button1).grid(row = 3,column = 0)

And the textbox:和文本框:

output = Text(window, width = 75, height=6, wrap=WORD, bg = "white")
output.grid(row = 13, column = 0)

Now I don't know what code to put in button command:现在我不知道在按钮命令中输入什么代码:

def button1():
    #idk what code to put
    #here, that will print
    #the letter 'A' in output
    #textbox

I'm new to tkinter so please help me with a piece of code that will print the letter "a" in output textbox.我是 tkinter 的新手,所以请帮我编写一段代码,该代码将在 output 文本框中打印字母“a”。 Thanks.谢谢。 No need of a huge explanation, jist a brief one to understand how it works.无需过多解释,只需简要说明一下即可了解其工作原理。

A minimalist example to get you started:一个让您入门的极简示例:

from tkinter import *  # for example purposes only!

def pressed():
    text.insert(END, 'Thank you!')

window = Tk()

Button(window, text="Press Me!", command=pressed).pack()

text = Text(window)
text.pack()

window.mainloop()

Now follow available tutorials to build upon this.现在按照可用的教程在此基础上进行构建。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM