带有 Tkinter 的 Python GUI

标签 python user-interface button tkinter

我在 python 中使用 gui 时遇到问题,程序会自动执行按钮创建中的命令选项。所以我陷入了一个循环。 ''' 创建于 5-mrt.-2012

@author: Max
'''
from Tkinter import *


class main(Tk):
    def __init__(self,parent):
        self.mainWindow()
    def mainWindow(self):
        '''Make the main window '''
        self.quitAll()
        self.app = Tk()
        self.app.title('NMBS application')
        self.makeAppButtons()
        self.finish(self.app)
    def makeAppButtons(self):
        '''Make all the buttons for the main menu'''
        button_lijn = Button(self.app, text="Voeg lijnritten toe", command = self.lijnritten())
        button_lijn.pack()
    def finish(self,window):
        ''' Make the main window'''
        window.mainloop()
    def endButton(self,window):
        '''Make a quit button'''
        button_back = Button(window,text="Sluiten",command = self.mainWindow())
        button_back.pack()
    def quitAll(self):
        '''Close all the current windows'''
        self.lijn_window.quit()
        self.app.quit()
    def lijnritten(self):
        ''' Make the lijnritten window'''
        self.app.quit()
        self.lijn_window = Tk()
        self.lijn_window.title("lijnritten")
        self.endButton(self.lijn_window)
        self.finish(self.lijn_window)
main(None)

最佳答案

当您链接命令时,不要使用 () 所以 command=self.action,就像这样。此外,这一行似乎给您带来了一些麻烦 self.quitAll()...不确定您要用它做什么,但这是我的两分钱。

''' 
Created on 5-mrt.-2012
@author: Max
'''
from Tkinter import *


class main(Tk):
    def __init__(self,parent):
        self.mainWindow()
    def mainWindow(self):
        '''Make the main window '''
        #self.quitAll()
        self.app = Tk()
        self.app.title('NMBS application')
        self.makeAppButtons()
        self.finish(self.app)
    def makeAppButtons(self):
        '''Make all the buttons for the main menu'''
        button_lijn = Button(self.app, text="Voeg lijnritten toe", command = self.lijnritten)
        button_lijn.pack()
    def finish(self,window):
        ''' Make the main window'''
        window.mainloop()
    def endButton(self,window):
        '''Make a quit button'''
        button_back = Button(window,text="Sluiten",command = self.mainWindow)
        button_back.pack()
    def quitAll(self):
        '''Close all the current windows'''
        self.lijn_window.quit()
        self.app.quit()
    def lijnritten(self):
        ''' Make the lijnritten window'''
        self.app.quit()
        self.lijn_window = Tk()
        self.lijn_window.title("lijnritten")
        self.endButton(self.lijn_window)
        self.finish(self.lijn_window)
main(None)

关于带有 Tkinter 的 Python GUI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9658365/

相关文章:

python - Html/Django - 从磁盘加载静态图像失败

python - 使用乘法 ( * ) 意外行为生成子列表

java - 当我在 JList 中单击文件时如何显示文件中的文本?

C# 检查文本文件是否有内容

html - 带前进/后退按钮、URL 加载器等的全功能 iFrame

jquery - jquery slider 上按钮的 z-index

python - Mac 上的 TensorFlow 安装错误

python - 如何获得所有可能的约束组合?

javascript - 如何让 Angular 组件占据屏幕的全高

Android M Light and Dark状态栏以编程方式 - 如何使其再次变暗?