[英]how do i change the color of the input text in tkinter?
from tkinter import *
import random
a = random.randint(1,10)
print(a)
root = Tk()
root.geometry("500x500")
root.title(" peleg's random number")
wrongtxt = "Wrong answer the number was, {}".format(a)
righttxt= "Correct the number was {}".format(a)
def Take_input():
INPUT = inputtxt.get("1.0", "end-1c",)
print(INPUT)
if (INPUT == format(a)):
Output.insert(END, righttxt)
else:
Output.insert(END, wrongtxt)
l = Label(text="pick a number between 1-10")
inputtxt = Text(root, height=10,
width=35,
bg="gray")
Output = Text(root, height=10,
width=35,
bg="black")
Display = Button(root, height=2,
bg="black",
width=20,
text="Show",
command=lambda: Take_input())
l.pack()
inputtxt.pack()
Display.pack()
Output.pack()
mainloop()
我的代碼非常簡單,但我似乎找不到關於如何更改您輸入的文本顏色的解決方案,我的意思是用戶正在編寫的輸入文本以及如何更改文本的顏色打印 output
使用fg
參數:
inputtxt = Text(root, height=10,
width=35,
bg="gray",
fg="red") # <- HERE
Output = Text(root, height=10,
width=35,
bg="black",
fg="red") # <- HERE
更新
我如何對根做同樣的事情,我的意思是屏幕的背景?
root.configure(background="red")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.