如何在 python 中更改使用 Tkinter 完成的文本框的背景颜色?我使用了下面的代码,但我不明白为什么它不起作用
from Tkinter import *
def onclick():
pass
root = Tk()
text = Text(root)
text.pack()
text.tag_add("here", "1.0", "1.4")
text.tag_add("start", "1.8", "1.13")
text.tag_config("here", background="black", foreground="green")
root.mainloop()
Run Code Online (Sandbox Code Playgroud) 我正在编写一个程序,如果你在文本框中放置一个文本,它会搜索Google.com上的内容,但它会返回一个错误:
TypeError: cannot concatenate 'str' and 'instance' objects
Run Code Online (Sandbox Code Playgroud)
这是代码:
InputStrings = StringVar()
Entry(root, textvariable = InputStrings).pack()
def OutputText():
OutStrings = InputStrings.get()
b = "https://www.google.it/search?q="
if InputStrings:
b = b + InputStrings
webbrowser.open(b)
root.withdraw()
root.quit()
Run Code Online (Sandbox Code Playgroud)