English 中文(简体)
在Tkinter使用Adhur时使用多个框架
原标题:Multiple frames in Tkinter while using Python

然而,我一直试图获得一个简单的全球倡议工作,接受使用Tkinter模块所包含的一种进入形式进行扼杀,并且视其所在的集装箱而定,要么使用“技能+扼杀”或通过终端“开放+扼杀”。 下面是我使用的法典。 问题符合第8条,上述评论更详细解释了错误。

from tkinter import *
import os
root = Tk()
def buttonPressed():
    # this is the problem in the program.
    # it keeps returning [  ] in the print statement and doesn t quit
    # any applications
    listOfApps = form1.form.get().split( , )
    # the print is just so i can see the output
    print(listOfApps)
    # goes through each item in list and kills them(yes i know there are much easier
    # ways to do this, i m just trying to learn a bit about GUI and the os module
    for i in listOfApps:
        try:
            os.system("killall " + i)
        except:
            pass
def buttonPressed2():
    filesToOpen = form2.form.get().split( ,  )
    for i in filesToOpen:
        try:
            os.system("open " + i)
        except:
            pass
class form_and_submit:
    def _init_(self):
        pass
    #creates an instance of a form with seperate variables for button text, buton command, and color of the frame
    def create_container(self, buttonText, buttonCommand, color):
        #Creating all widgets/containers
        self.container = Frame(root)
        self.form = Entry(self.container)
        self.button = Button(self.container)
        #defining variables for all widgets/containers
        root[ background ] = color
        self.container[ background ] = color
        self.button[ text ] = buttonText
        self.button[ command ] = buttonCommand
        self.form[ background ] = color
        self.form[ border ] =  5 
        self.form[ highlightthickness ] =  0 
        #Packing all widgets/containers
        self.container.pack()
        self.form.pack()
        self.button.pack()
#creating forms and putting them in root with desire attributes
form1 = form_and_submit
form2 = form_and_submit
form1.create_container(form1,  kill matching processes , buttonPressed,  red )
form2.create_container(form2,  Open desired files , buttonPressed2,  blue )
#starts up window
root.mainloop()

我认为,这里的问题属于多个范畴,因为这个问题在作为阶级形式的例子——和——提交之前做了罚款。 事先感谢你帮助解决这一问题的任何人。

问题回答

这或许不是你所寻求的答案,但我可以通过摆脱这一阶层来这样做。 在这方面,我已经:

from tkinter import *
import os
root = Tk()

def buttonPressed():
    # this is the problem in the program.
    # it keeps returning [  ] in the print statement and doesn t quit
    # any applications
    listOfApps = form.get().split( , )
    # the print is just so i can see the output
    print(listOfApps)
    # goes through each item in list and kills them(yes i know there are much easier
    # ways to do this, i m just trying to learn a bit about GUI and the os module
    for i in listOfApps:
        try:
            os.system("killall " + i)
        except:
            pass
def buttonPressed2():
    filesToOpen = form2.get().split( ,  )
    for i in filesToOpen:
        try:
            os.system("open " + i)
        except:
            pass

container = Frame(root)
form = Entry(container)
button = Button(container)
root[ background ] =  red 
container[ background ] =  red 
button[ text ] =  kill matching processes 
button[ command ] = buttonPressed
form[ background ] =  red 
form[ border ] =  5 
form[ highlightthickness ] =  0 


container2 = Frame(root)
form2 = Entry(container2)
button2 = Button(container2)
root[ background ] =  blue 
container2[ background ] =  blue 
button2[ text ] =  Open desired files 
button2[ command ] = buttonPressed2
form2[ background ] =  blue 
form2[ border ] =  5 
form2[ highlightthickness ] =  0 

container.pack()
form.pack()
button.pack()

container2.pack()
form2.pack()
button2.pack()

#starts up window
root.mainloop()




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签