-1

水平学生在计算我的第二年项目,并决定尝试创建一个实用程序来访问 USB 驱动器并返回不同文件和文件夹在 GUI 中占用 USB 空间的百分比值(GUI 代码) .

from tkinter import *
from tkinter.ttk import *
def select():
    sf = "value is %s" % var.get()
    root.title(sf)
    # optional
    color = var.get()
    root['bg'] = color
root = Tk()

# use width x height + x_offset + y_offset (no spaces!)
root.geometry("%dx%d+%d+%d" % (1000, 600, 10, 10))
root.title("USB scanner")
frame1=Frame(root)
frame1.pack(side=TOP, anchor=W)
var = StringVar(root)
# initial value

var.set('select drive')
choices = ['', '', '', '','', '']
option = OptionMenu(frame1, var, *choices)
option.pack(side=LEFT)
button = Button(frame1, text="Scan selected drive", command=select)
button.pack(side=LEFT, padx=30, pady=30)

root.mainloop()

我已经安装了 pyUSB-1.0.0a2 和 libopenusb-1.1.11 我不断收到后端不可用错误我检查了 DLL。如果我说实话,我不知道我在做什么,所以任何基本的帮助都会受到赞赏

4

1 回答 1

0

以下程序应该可以帮助您指出正确的方向:

from tkinter import *
from shutil import disk_usage

class Sizer(Frame):

    @classmethod
    def main(cls):
        NoDefaultRoot()
        root = Tk()
        root.geometry('{}x{}'.format(200, 100))
        root.resizable(False, False)
        root.title('Drive Information')
        widget = cls(root)
        widget.grid(row=0, column=0, sticky=NSEW)
        root.mainloop()

    def __init__(self, master=None, cnf={}, **kw):
        super().__init__(master, cnf, **kw)
        self.selection = StringVar(self)
        self.menu = OptionMenu(self, self.selection, 'A:\\', 'B:\\', 'C:\\')
        self.menu.grid(row=0, column=0, sticky=NSEW)
        self.button = Button(self, text='Scan the drive', command=self.scan)
        self.button.grid(row=1, column=0, sticky=NSEW)
        self.display = Label(self)
        self.display.grid(row=2, column=0, sticky=NSEW)

    def scan(self):
        disk = self.selection.get()
        try:
            information = disk_usage(disk)
        except FileNotFoundError:
            self.display['text'] = 'Disk {!r} cound not be found'.format(disk)
        else:
            self.display['text'] = 'Used: {}\nFree: {}'.format(
                information.used, information.free)

if __name__ == '__main__':
    Sizer.main()
于 2014-10-22T17:36:35.823 回答