gpt4 book ai didi

python - 在 Ubuntu 上的 TextBox Tkinter Python 中打印

转载 作者:行者123 更新时间:2023-12-04 18:58:00 25 4
gpt4 key购买 nike

我不知道我到底应该怎么称呼这个问题,所以如果不完全理解,请编辑。
我正在 Ubuntu 上用 Python 编写一个程序,用 Y 轴滚动选项在 TextBox 中打印文件名。

但是文件名出现在文本框之外,并且滚动选项也无法正常工作。
我还附上了下面程序的输出
enter image description here

你能请我解决这个问题吗?

import io,sys,os,subprocess 
from Tkinter import *

def viewFile():
s=1
for f in os.listdir(path):
var= StringVar()
var.set(f)
l1 = Label(mainframe, textvariable=var)
l1.grid(row=s)
s += 1

if __name__ == '__main__':
root = Tk()

mainframe= root.title("FILE MANAGER APPLICATION") # Program Objective
mainframe= root.attributes('-fullscreen', True)

step = LabelFrame(root,text="FILE MANAGER", font = "Arial 20 bold italic")
step.grid(row=0, columnspan=7, sticky='W',padx=100, pady=5, ipadx=130, ipady=25)

Button(step, text="File View", font = "Arial 8 bold italic", activebackground="turquoise", width=30, height=5, command=viewFile).grid (row= 1, column =2)
Button(step, text="Exit", font = "Arial 8 bold italic", activebackground="turquoise", width=20, height=5, command=root.quit).grid (row= 1, column =5)

tex = Text(master=root)
scr=Scrollbar(root,orient =VERTICAL,command=tex.yview)
scr.grid(row=2, column=2, rowspan=15, columnspan=1, sticky=NS)
tex.grid(row=2, column=1, sticky=W)
tex.config(yscrollcommand=scr.set,font=('Arial', 8, 'bold', 'italic'))

global process
path = os.path.expanduser("~/python") # Define path To play, delete, or rename video
root.mainloop()

最佳答案

如果你想在 tex 中插入文件名,然后调用tex.insert而不是创建新标签。

def viewFile():
for f in os.listdir(path):
tex.insert(END, f + "\n")

关于python - 在 Ubuntu 上的 TextBox Tkinter Python 中打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27948226/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com