小班很烦人



我一直在尝试完成tkinter的最基本的工作,只是为了在尝试学习其他内容之前能够将一些输入字段的内容打印到控制台中。我让它看起来像我想要的那样,但没有我需要的功能。有人建议我创建一个类并这样做,此时我的GUI是一个空框架,没有我添加的任何小部件。有人知道这是为什么吗?

from tkinter import *
class Information:
    def __init__(self, master):
        frame = Frame(master)
        frame.pack()
        self.titleLabel = Label(frame, text='Welcome to the Redaction Solutions editor!nPlease enter the requested filepaths below.')
        self.titleLabel.pack(side=TOP)
        self.originalLabel = Label(frame, text='File to be edited')
        self.originalLabel.pack(side=LEFT)
        self.originalEntry = Entry(frame)
        self.originalEntry.pack(side=RIGHT)
        self.namesLabel = Label(frame, text='Items to be removed')
        self.namesLabel.pack(side=LEFT)
        self.namesEntry = Entry(frame)
        self.namesEntry.pack(side=RIGHT)
        self.destinationLabel = Label(frame, text='Edited file')
        self.destinationLabel.pack(side=LEFT)
        self.destinationEntry = Entry(frame)
        self.destinationEntry.pack(side=RIGHT)
        self.invoiceLabel = Label(frame, text='Invoice data')
        self.invoiceLabel.pack(side=LEFT)
        self.invoiceEntry = Entry(frame)
        self.invoiceEntry.pack(side=RIGHT)
        self.demoButton = Button(frame, text="Test", command=self.test)
        self.demoButton.pack(side=LEFT)
        self.resetButton = Button(frame, text="Reset Fields", bg="red", fg="black", command=self.reset)
        self.resetButton.pack(side=RIGHT)
    def test(self):
        print(self.originalEntry.get())
        print(self.namesEntry.get())
        print(self.destinationEntry.get())
        print(self.invoiceEntry.get())
    def reset(self):
        self.originalEntry.delete(0, END)
        self.namesEntry.delete(0, END)
        self.destinationEntry.delete(0, END)
        self.invoiceEntry.delete(0, END)
root = Tk()
root.wm_title("RS")
b = Information
root.iconbitmap(r'c:UserspbrowDocumentslogoicon.ico')
root.mainloop()

我也有99%的把握这大概是写这个程序最糟糕的方式…我不介意我只是想让它正常工作,我已经放弃了自己担心优化在(很多)以后的日期

不要介意我之前的回答。问题是:

root = Tk()
root.wm_title("RS")
b = Information
root.iconbitmap(r'c:UserspbrowDocumentslogoicon.ico')
root.mainloop()

你应该做的是:

b = Information(root)

来实际创建Information对象

相关内容

  • 没有找到相关文章

最新更新