self.log_box = tk.Text(self.log_frame, height=40, width=200, state=tk.NORMAL)修改為不可編輯
时间: 2023-11-22 08:55:58 浏览: 35
可以将state设置为tk.DISABLED,这样文本框就不能编辑了,修改后的代码如下:
```
self.log_box = tk.Text(self.log_frame, height=40, width=200, state=tk.DISABLED)
```
相关问题
self.log_box = tk.Text(self.log_frame, height=40, width=200, state=tk.DISABLED)修改文本框可以正常顯示數據,但不能更改
那是因为你设置了`state=tk.DISABLED`,这会禁用文本框的编辑功能。如果你想让文本框可以编辑,可以将其状态改为`state=tk.NORMAL`。例如:
```
self.log_box = tk.Text(self.log_frame, height=40, width=200, state=tk.NORMAL)
```
这样就可以在文本框中编辑文本了。
# 创建右侧面板 self.panel_right = tk.Frame(master, bg='white') self.panel_right.pack(side=tk.LEFT, fill=tk.BOTH, expand=True) # 创建文本框 text_frame = tk.Frame(self.panel_right) text_frame.pack(side=tk.TOP, fill=tk.BOTH, expand=True) self.result_text = tk.Text(text_frame) self.result_text.pack(side=tk.TOP, fill=tk.BOTH, expand=True)在這段代碼中再添加一個右下方添加一個文本框
可以在 `self.panel_right` 中再添加一个 `text_frame2`,然后在 `text_frame2` 中创建一个 `tk.Text` 对象。以下是示例代码:
```
# 创建右侧面板
self.panel_right = tk.Frame(master, bg='white')
self.panel_right.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
# 创建文本框1
text_frame = tk.Frame(self.panel_right)
text_frame.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
self.result_text = tk.Text(text_frame)
self.result_text.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
# 创建文本框2
text_frame2 = tk.Frame(self.panel_right)
text_frame2.pack(side=tk.BOTTOM, fill=tk.BOTH, expand=True)
self.result_text2 = tk.Text(text_frame2)
self.result_text2.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
```
这样就在右侧面板的底部添加了一个新的文本框 `self.result_text2`。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)