ttk.Button(self.master, text="取消", command=self.master.destroy, style="TButton").grid(row=2, column=2, columnspan=1, padx=10, pady=10)修改字體顔色為藍色
时间: 2024-03-01 12:50:55 浏览: 90
如果你想将按钮的字体颜色修改为蓝色,可以将 `foreground` 参数的值改为蓝色的颜色代码,例如 `"blue"` 或 `"#0000FF"`。修改后的代码如下:
```
style.configure("TButton", background="#4CAF50", foreground="blue", font=("Helvetica", 12), width=10)
ttk.Button(self.master, text="取消", command=self.master.destroy, style="TButton").grid(row=2, column=2, columnspan=1, padx=10, pady=10)
```
这里将 `foreground` 参数的值设置为蓝色的颜色代码 `"#0000FF"`,这样按钮的字体颜色就会被修改为蓝色。
相关问题
ttk.Button(self.master, text="確認", command=self.login, style="TButton").grid(row=2, column=0, columnspan=1,padx=10, pady=10) ttk.Button(self.master, text="取消", command=self.master.destroy, style="TButton").grid(row=2, column=2, columnspan=1, padx=10, pady=10)修改這個按鈕,太小了,改打一些
Sure, here's an example of how you can increase the size of the buttons:
```
ttk.Button(self.master, text="確認", command=self.login, style="TButton", width=15, height=2).grid(row=2, column=0, columnspan=1, padx=10, pady=10)
ttk.Button(self.master, text="取消", command=self.master.destroy, style="TButton", width=15, height=2).grid(row=2, column=2, columnspan=1, padx=10, pady=10)
```
In this example, the `width` parameter sets the width of the button in characters and the `height` parameter sets the height of the button in lines. You can adjust these parameters to increase or decrease the size of the buttons as desired.
class LoginWindow: def init(self, master): self.master = master self.master.title("CQ SMT BL 監控平臺-003無紙化點檢系統") self.master.geometry("300x250+400+250") self.master.resizable(0, 0) self.username = tk.StringVar() self.password = tk.StringVar() ttk.Label(self.master, text="賬號:", width=10).grid(row=0, column=0, padx=10, pady=10) ttk.Entry(self.master, textvariable=self.username, width=50).grid(row=0, column=1, columnspan=1, padx=10, pady=10) ttk.Label(self.master, text="密碼:", width=10).grid(row=1, column=0, padx=10, pady=10) ttk.Entry(self.master, textvariable=self.password, show="*", width=50).grid(row=1, column=1, columnspan=1, padx=10, pady=10) style = ttk.Style() style.configure("TButton", background="#4CAF50", foreground="blue", font=("Helvetica", 12), width=10) ttk.Button(self.master, text="確認", command=self.login, style="TButton", width=20).grid(row=2, column=0, columnspan=1, padx=10, pady=10) ttk.Button(self.master, text="取消", command=self.master.destroy, style="TButton", width=20).grid(row=2, column=2, columnspan=1, padx=10, pady=10) # 设置列的宽度 self.master.grid_columnconfigure(0, weight=1) self.master.grid_columnconfigure(1, weight=1) self.master.grid_columnconfigure(2, weight=1)修改這段代碼中將這個窗口分成兩個面板,從文本標簽到按鈕中間分割
你可以使用 ttk.Panedwindow() 来将窗口分成两个面板。以下是修改后的代码:
```
class LoginWindow:
def __init__(self, master):
self.master = master
self.master.title("CQ SMT BL 監控平臺-003無紙化點檢系統")
self.master.geometry("300x250+400+250")
self.master.resizable(0, 0)
self.username = tk.StringVar()
self.password = tk.StringVar()
# 创建一个 Panedwindow,设置 orient 为水平方向
pw = ttk.Panedwindow(self.master, orient='horizontal')
pw.pack(fill='both', expand=True)
# 创建左侧面板
left_frame = ttk.Frame(pw, width=150, height=250, relief='sunken')
pw.add(left_frame)
# 创建右侧面板
right_frame = ttk.Frame(pw, width=150, height=250, relief='sunken')
pw.add(right_frame)
# 在左侧面板中添加控件
ttk.Label(left_frame, text="賬號:", width=10).grid(row=0, column=0, padx=10, pady=10)
ttk.Entry(left_frame, textvariable=self.username, width=50).grid(row=0, column=1, columnspan=1, padx=10, pady=10)
ttk.Label(left_frame, text="密碼:", width=10).grid(row=1, column=0, padx=10, pady=10)
ttk.Entry(left_frame, textvariable=self.password, show="*", width=50).grid(row=1, column=1, columnspan=1, padx=10, pady=10)
# 在右侧面板中添加控件
style = ttk.Style()
style.configure("TButton", background="#4CAF50", foreground="blue", font=("Helvetica", 12), width=10)
ttk.Button(right_frame, text="確認", command=self.login, style="TButton", width=20).grid(row=0, column=0, columnspan=1, padx=10, pady=10)
ttk.Button(right_frame, text="取消", command=self.master.destroy, style="TButton", width=20).grid(row=1, column=0, columnspan=1, padx=10, pady=10)
# 设置左右侧面板的列宽
left_frame.grid_columnconfigure(0, weight=1)
left_frame.grid_columnconfigure(1, weight=1)
right_frame.grid_columnconfigure(0, weight=1)
```
阅读全文