Python GUI。在同一个类中调用另一个函数

时间:2014-05-18 10:14:09

标签: python python-2.7 tkinter

我是python中的新手。有人可以帮我这个代码吗?我不知道如何解决它。

from Tkinter import *

class Application(Frame):
    """ GUI Application for Simulation"""
    def __init__(self, master):

        """Initialize frame"""
        Frame.__init__(self, master)
        self.grid()
        self.create_widgets()


    def create_widgets(self):


        Label(self, text = "Welcome!").grid(row = 0, column = 0, columnspan = 2, sticky = W)


        Label(self, text= "Type of Computing:").grid(row = 1, column = 0, sticky = W)


        self.is_parallel = BooleanVar()
        Checkbutton(self, 
                    text = "Parallel Computing",
                    variable = self.is_parallel
                    ).grid(row = 1, column = 1, sticky = W)


        self.is_distributed = BooleanVar()
        Checkbutton(self,
                    text = "Distributed Computing",
                    variable = self.is_distributed 
                    ).grid(row = 1, column = 2, sticky = W)


        Label(self, text= "Enter Number of Processor").grid(row = 2, column = 0, sticky = W)
        self.processor_ent = Entry(self)
        self.processor_ent.grid(row = 2, column = 1, sticky = W)





        Label(self, text = "Choose the type of task").grid(row = 3, column = 0, sticky = W)     
        self.task = StringVar()
        task = ["Chat Message", "Calculation"]
        column = 1
        for part in task:
            Radiobutton(self,
                        text = part,
                        variable = self.task,
                        value = part
                        ).grid(row = 3, column = column, sticky = W)

            column += 1


        Label(self, text = "Click 'Run' to run this simulation").grid(row = 4, column = 0, sticky = W)


        Button(self,
               text = "Run",
              command = self.run_simulation
               ).grid(row = 4, column = 1, sticky = W)


        self.run_simulation_txt(self, width = 75, height = 15, wrap = WORD)
        self.run_simulation_txt.grid(row = 12, column = 0, columnspan = 4)




    def run_simulation(self):
        """Fill the box to run the simulation"""


            if self.is_parallel.get()
                Computing += "Parallel Computing"

            if self.is_distributed.get()
                Computing += "Distributed Computing"

            processor = self.processor_ent.get()

            task = self.task.get()

#main
root = Tk()
root.title("Computing Simulation")
root.geometry("700x550")
app = Application(root)
root.mainloop()

我想用下拉菜单替换此代码而不是作为文本条目,但我无法弄清楚如何。我做了一些搜索和研究,但仍然模糊。

Label(self, text= "Enter Number of Processor").grid(row = 2, column = 0, sticky = W)
    self.processor_ent = Entry(self)
    self.processor_ent.grid(row = 2, column = 1, sticky = W)

0 个答案:

没有答案