我正在尝试创建一个按钮,该按钮将包括一个左对齐的图像和一个右对齐的文本。我只想通过参数“文本”来更改文本,而不是通过修改整个图像。这有可能吗?
这是一个简单的例子,我的意思。
http://img651.imageshack.us/img651/3776/previewrv.png
希望我解释得很好
谢谢
查看compound
标签的选项。它允许您指定标签与文本的关系(上、下、左、右、无)。
例如:
import Tkinter as tk
class View(tk.Frame):
def __init__(self, *args, **kwargs):
tk.Frame.__init__(self, *args, **kwargs)
self.image = tk.PhotoImage(file="somefile.gif")
b = tk.Button(self, text="Hello, world", image=self.image, compound="left")
b.pack(side="top")
if __name__ == "__main__":
root = tk.Tk()
view = View(root)
view.pack(side="top", fill="both", expand=True)
root.mainloop()