[英]Python tkinter button command
我想制作一個應用程序,如果您按下按鈕,它將在文本框中打印一個字母。 我創建了按鈕:
Button(window, text="Button1", width=5,command = button1).grid(row = 3,column = 0)
和文本框:
output = Text(window, width = 75, height=6, wrap=WORD, bg = "white")
output.grid(row = 13, column = 0)
現在我不知道在按鈕命令中輸入什么代碼:
def button1():
#idk what code to put
#here, that will print
#the letter 'A' in output
#textbox
我是 tkinter 的新手,所以請幫我編寫一段代碼,該代碼將在 output 文本框中打印字母“a”。 謝謝。 無需過多解釋,只需簡要說明一下即可了解其工作原理。
一個讓您入門的極簡示例:
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()
現在按照可用的教程在此基礎上進行構建。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.