0
以下代碼用於創建具有tkinter的Text()函數的表。我想添加一個滾動條到這個窗口,但我猜想當我將滾動條添加到Text()時,此方法不用於滾動窗口,它用於在Text()內滾動。如何使用tkinter爲文本創建表添加滾動條
我沒有添加幾何到這個例子。當前幾何圖形取決於行和列的數量。但是假設請求的是固定的幾何尺寸,並且當我們寫入行數和列數時,我們應該看到帶有該滾動條的其他行和列。
from tkinter import *
class Application:
def __init__(self):
self.window = Tk()
self.window.title("Database")
self.window.resizable(width=False, height=False)
self.frame_1 = Frame(bg="black")
self.frame_1.grid(row=0, column=0)
self.menubar = Menu(tearoff=0)
self.table()
self.menu()
self.mainloop = self.window.mainloop()
def table(self):
row = int(input("Row:"))
column = int(input("Column:"))
for i in range(row):
for j in range(column):
text = Text(self.frame_1, width=20, height=1)
text.bind("<Button-3>", self.popup)
text.grid(row=i, column=j, padx=1, pady=1)
text.configure(state="disabled")
def menu(self):
self.menubar.add_command(label="Copy", command=lambda: self.window.focus_get().event_generate('<<Copy>>'))
def popup(self, event):
self.menubar.post(event.x_root, event.y_root)
哦,謝謝你,我正在看鏈接。 –
我根據你寫的帖子修改了代碼。我把滾動條都放到x和y軸上。你寫的代碼正在工作。但我想問一個關於行和列數量的不同問題。例如根據測試,max row * col是18 * 18,當我鍵入19 * 19時,程序正在等待計算。它也接受100 * 3但不接受100 * 4。你知道原因嗎? –
@dildeolupbiten:如果你想問另一個問題,請點擊「Ask Question」按鈕。 Stackoverflow不是用來支持評論中的長談話。 –