tkinter display new frame from menu












0















I'm trying to write my fisrt script in python & tkinter.



I block to display a new frame from a function (def onDisplay) when a click is made from menu bar button, but nothing append.
No error is display :-(



The new frame is made with dynamic checkboxes from text files:
txt file:



item1
item2
...
item100


A screen of the GUI:



enter image description here



Here my code:



from tkinter import Tk, Frame, Menu, Checkbutton, Text, TOP, BOTH, X, N, LEFT, BooleanVar
from tkinter.ttk import Frame, Label, Entry
import glob

class Example(Frame):

def __init__(self):
super().__init__()

self.initUI()
#self.display_srv()

def initUI(self):

self.master.title("Submenu")

menubar = Menu(self.master)
self.master.config(menu=menubar)

fileMenu = Menu(menubar)

submenu = Menu(fileMenu)
submenu.add_command(label="lst1", command=self.onDisplay)
submenu.add_command(label="lst2")
submenu.add_command(label="lst3")
fileMenu.add_cascade(label='Listing', menu=submenu, underline=0)

fileMenu.add_separator()

fileMenu.add_command(label="Exit", underline=0, command=self.onExit)
menubar.add_cascade(label="File", underline=0, menu=fileMenu)

#The frame i tried to display
def onDisplay(self):
self.master.title("display it")
self.pack(fill=BOTH, expand=True)
frame1 = Frame(self)
frame1.pack(fill=X)
path = '/root/liste/*.txt'
files=glob.glob(path)
count = 0
for file in files:
with open(file, 'r') as lst_file:
for item in lst_file:
# Need to split all item by 10
Checkbutton(self, text=item.rstrip()).grid(row=count//10, column=count%10)
count += 1


def onClick(self):
if self.var.get() == True:
self.master.title("Checkbutton")
else:
self.master.title("")

def onExit(self):

self.quit()


def main():

root = Tk()
root.geometry("850x550+300+300")
app = Example()
root.mainloop()


if __name__ == '__main__':


Many thanks for any help



Regards,










share|improve this question























  • What have you done to debug this? Have you verified that files=glob.glob(path) is doing what you think?

    – Bryan Oakley
    Nov 15 '18 at 15:45











  • yes, i used this part of this code in a standalone script, without menu bar.

    – Indi59
    Nov 15 '18 at 16:01











  • That code, mixing .pack(... with .grid(..., will never work. Take the tour and reread how it works tkinterbook

    – stovfl
    Nov 15 '18 at 16:14











  • ok, thank you for the link stovfl. I replace by .pack: Checkbutton(self, text=item.rstrip()).pack but the issue is the same.. :-/

    – Indi59
    Nov 15 '18 at 16:33


















0















I'm trying to write my fisrt script in python & tkinter.



I block to display a new frame from a function (def onDisplay) when a click is made from menu bar button, but nothing append.
No error is display :-(



The new frame is made with dynamic checkboxes from text files:
txt file:



item1
item2
...
item100


A screen of the GUI:



enter image description here



Here my code:



from tkinter import Tk, Frame, Menu, Checkbutton, Text, TOP, BOTH, X, N, LEFT, BooleanVar
from tkinter.ttk import Frame, Label, Entry
import glob

class Example(Frame):

def __init__(self):
super().__init__()

self.initUI()
#self.display_srv()

def initUI(self):

self.master.title("Submenu")

menubar = Menu(self.master)
self.master.config(menu=menubar)

fileMenu = Menu(menubar)

submenu = Menu(fileMenu)
submenu.add_command(label="lst1", command=self.onDisplay)
submenu.add_command(label="lst2")
submenu.add_command(label="lst3")
fileMenu.add_cascade(label='Listing', menu=submenu, underline=0)

fileMenu.add_separator()

fileMenu.add_command(label="Exit", underline=0, command=self.onExit)
menubar.add_cascade(label="File", underline=0, menu=fileMenu)

#The frame i tried to display
def onDisplay(self):
self.master.title("display it")
self.pack(fill=BOTH, expand=True)
frame1 = Frame(self)
frame1.pack(fill=X)
path = '/root/liste/*.txt'
files=glob.glob(path)
count = 0
for file in files:
with open(file, 'r') as lst_file:
for item in lst_file:
# Need to split all item by 10
Checkbutton(self, text=item.rstrip()).grid(row=count//10, column=count%10)
count += 1


def onClick(self):
if self.var.get() == True:
self.master.title("Checkbutton")
else:
self.master.title("")

def onExit(self):

self.quit()


def main():

root = Tk()
root.geometry("850x550+300+300")
app = Example()
root.mainloop()


if __name__ == '__main__':


Many thanks for any help



Regards,










share|improve this question























  • What have you done to debug this? Have you verified that files=glob.glob(path) is doing what you think?

    – Bryan Oakley
    Nov 15 '18 at 15:45











  • yes, i used this part of this code in a standalone script, without menu bar.

    – Indi59
    Nov 15 '18 at 16:01











  • That code, mixing .pack(... with .grid(..., will never work. Take the tour and reread how it works tkinterbook

    – stovfl
    Nov 15 '18 at 16:14











  • ok, thank you for the link stovfl. I replace by .pack: Checkbutton(self, text=item.rstrip()).pack but the issue is the same.. :-/

    – Indi59
    Nov 15 '18 at 16:33
















0












0








0








I'm trying to write my fisrt script in python & tkinter.



I block to display a new frame from a function (def onDisplay) when a click is made from menu bar button, but nothing append.
No error is display :-(



The new frame is made with dynamic checkboxes from text files:
txt file:



item1
item2
...
item100


A screen of the GUI:



enter image description here



Here my code:



from tkinter import Tk, Frame, Menu, Checkbutton, Text, TOP, BOTH, X, N, LEFT, BooleanVar
from tkinter.ttk import Frame, Label, Entry
import glob

class Example(Frame):

def __init__(self):
super().__init__()

self.initUI()
#self.display_srv()

def initUI(self):

self.master.title("Submenu")

menubar = Menu(self.master)
self.master.config(menu=menubar)

fileMenu = Menu(menubar)

submenu = Menu(fileMenu)
submenu.add_command(label="lst1", command=self.onDisplay)
submenu.add_command(label="lst2")
submenu.add_command(label="lst3")
fileMenu.add_cascade(label='Listing', menu=submenu, underline=0)

fileMenu.add_separator()

fileMenu.add_command(label="Exit", underline=0, command=self.onExit)
menubar.add_cascade(label="File", underline=0, menu=fileMenu)

#The frame i tried to display
def onDisplay(self):
self.master.title("display it")
self.pack(fill=BOTH, expand=True)
frame1 = Frame(self)
frame1.pack(fill=X)
path = '/root/liste/*.txt'
files=glob.glob(path)
count = 0
for file in files:
with open(file, 'r') as lst_file:
for item in lst_file:
# Need to split all item by 10
Checkbutton(self, text=item.rstrip()).grid(row=count//10, column=count%10)
count += 1


def onClick(self):
if self.var.get() == True:
self.master.title("Checkbutton")
else:
self.master.title("")

def onExit(self):

self.quit()


def main():

root = Tk()
root.geometry("850x550+300+300")
app = Example()
root.mainloop()


if __name__ == '__main__':


Many thanks for any help



Regards,










share|improve this question














I'm trying to write my fisrt script in python & tkinter.



I block to display a new frame from a function (def onDisplay) when a click is made from menu bar button, but nothing append.
No error is display :-(



The new frame is made with dynamic checkboxes from text files:
txt file:



item1
item2
...
item100


A screen of the GUI:



enter image description here



Here my code:



from tkinter import Tk, Frame, Menu, Checkbutton, Text, TOP, BOTH, X, N, LEFT, BooleanVar
from tkinter.ttk import Frame, Label, Entry
import glob

class Example(Frame):

def __init__(self):
super().__init__()

self.initUI()
#self.display_srv()

def initUI(self):

self.master.title("Submenu")

menubar = Menu(self.master)
self.master.config(menu=menubar)

fileMenu = Menu(menubar)

submenu = Menu(fileMenu)
submenu.add_command(label="lst1", command=self.onDisplay)
submenu.add_command(label="lst2")
submenu.add_command(label="lst3")
fileMenu.add_cascade(label='Listing', menu=submenu, underline=0)

fileMenu.add_separator()

fileMenu.add_command(label="Exit", underline=0, command=self.onExit)
menubar.add_cascade(label="File", underline=0, menu=fileMenu)

#The frame i tried to display
def onDisplay(self):
self.master.title("display it")
self.pack(fill=BOTH, expand=True)
frame1 = Frame(self)
frame1.pack(fill=X)
path = '/root/liste/*.txt'
files=glob.glob(path)
count = 0
for file in files:
with open(file, 'r') as lst_file:
for item in lst_file:
# Need to split all item by 10
Checkbutton(self, text=item.rstrip()).grid(row=count//10, column=count%10)
count += 1


def onClick(self):
if self.var.get() == True:
self.master.title("Checkbutton")
else:
self.master.title("")

def onExit(self):

self.quit()


def main():

root = Tk()
root.geometry("850x550+300+300")
app = Example()
root.mainloop()


if __name__ == '__main__':


Many thanks for any help



Regards,







python checkbox tkinter dynamic frame






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 15:32









Indi59Indi59

526




526













  • What have you done to debug this? Have you verified that files=glob.glob(path) is doing what you think?

    – Bryan Oakley
    Nov 15 '18 at 15:45











  • yes, i used this part of this code in a standalone script, without menu bar.

    – Indi59
    Nov 15 '18 at 16:01











  • That code, mixing .pack(... with .grid(..., will never work. Take the tour and reread how it works tkinterbook

    – stovfl
    Nov 15 '18 at 16:14











  • ok, thank you for the link stovfl. I replace by .pack: Checkbutton(self, text=item.rstrip()).pack but the issue is the same.. :-/

    – Indi59
    Nov 15 '18 at 16:33





















  • What have you done to debug this? Have you verified that files=glob.glob(path) is doing what you think?

    – Bryan Oakley
    Nov 15 '18 at 15:45











  • yes, i used this part of this code in a standalone script, without menu bar.

    – Indi59
    Nov 15 '18 at 16:01











  • That code, mixing .pack(... with .grid(..., will never work. Take the tour and reread how it works tkinterbook

    – stovfl
    Nov 15 '18 at 16:14











  • ok, thank you for the link stovfl. I replace by .pack: Checkbutton(self, text=item.rstrip()).pack but the issue is the same.. :-/

    – Indi59
    Nov 15 '18 at 16:33



















What have you done to debug this? Have you verified that files=glob.glob(path) is doing what you think?

– Bryan Oakley
Nov 15 '18 at 15:45





What have you done to debug this? Have you verified that files=glob.glob(path) is doing what you think?

– Bryan Oakley
Nov 15 '18 at 15:45













yes, i used this part of this code in a standalone script, without menu bar.

– Indi59
Nov 15 '18 at 16:01





yes, i used this part of this code in a standalone script, without menu bar.

– Indi59
Nov 15 '18 at 16:01













That code, mixing .pack(... with .grid(..., will never work. Take the tour and reread how it works tkinterbook

– stovfl
Nov 15 '18 at 16:14





That code, mixing .pack(... with .grid(..., will never work. Take the tour and reread how it works tkinterbook

– stovfl
Nov 15 '18 at 16:14













ok, thank you for the link stovfl. I replace by .pack: Checkbutton(self, text=item.rstrip()).pack but the issue is the same.. :-/

– Indi59
Nov 15 '18 at 16:33







ok, thank you for the link stovfl. I replace by .pack: Checkbutton(self, text=item.rstrip()).pack but the issue is the same.. :-/

– Indi59
Nov 15 '18 at 16:33














2 Answers
2






active

oldest

votes


















0














The main problem is that you're mixing grid and pack in the same parent container. You are calling pack on frame1 but you are calling grid on the checkbuttons, and they both have a master or parent of self.



That can't work, because each of grid and pack will try to resize the container according to it's rules, triggering the other one to reconfigure according to it's rules, and so on until the end of time.



So, simply changing your call of .grid(...) to .pack(...) on the checkbuttons will fix that problem.



My guess is that you intended to put the checkbuttons inside frame1. If that's the case, you need to specify frame1 as the master for the checkbuttons. For readability and ease of debugging I also recommend placing the call to grid on a separate line. With that, you can continue to use grid for the checkbuttons and pack for everything else.



cb = Checkbutton(frame1, text=item.rstrip())
cb.grid(row=count//10, column=count%10)





share|improve this answer
























  • Many thanks Bryan, i understand better now. I started to use python since few days.. :). I got another issue on my code. I will create a new topic on Stack today or tomorrow. If is possible for you to take look please.I search how to get the values of each selected items.

    – Indi59
    Nov 15 '18 at 17:11



















0














I posted the correct code:



from tkinter import Tk, Frame, Menu, Checkbutton, Text, TOP, BOTH, X, N, LEFT, BooleanVar
from tkinter.ttk import Frame, Label, Entry
import glob

class Example(Frame):

def __init__(self):
super().__init__()

self.initUI()
#self.display_srv()

def initUI(self):

self.master.title("Submenu")

menubar = Menu(self.master)
self.master.config(menu=menubar)

fileMenu = Menu(menubar)

submenu = Menu(fileMenu)
submenu.add_command(label="lst1", command=self.onDisplay)
submenu.add_command(label="lst2")
submenu.add_command(label="lst3")
fileMenu.add_cascade(label='Listing', menu=submenu, underline=0)

fileMenu.add_separator()

fileMenu.add_command(label="Exit", underline=0, command=self.onExit)
menubar.add_cascade(label="File", underline=0, menu=fileMenu)
def onDisplay(self):
self.master.title("display it")
self.pack(fill=BOTH, expand=True)
frame1 = Frame(self)
frame1.pack(fill=X)
path = '/root/liste/*.txt'
files=glob.glob(path)
count = 0
for file in files:
with open(file, 'r') as lst_file:
for item in lst_file:
cb = Checkbutton(frame1, text=item.rstrip())
cb.grid(row=count//10, column=count%10)
count += 1

def onClick(self):
if self.var.get() == True:
self.master.title("Checkbutton")
else:
self.master.title("")

def onExit(self):

self.quit()

def main():

root = Tk()
root.geometry("850x550+300+300")
app = Example()
root.mainloop()

if __name__ == '__main__':
main()





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53322791%2ftkinter-display-new-frame-from-menu%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    The main problem is that you're mixing grid and pack in the same parent container. You are calling pack on frame1 but you are calling grid on the checkbuttons, and they both have a master or parent of self.



    That can't work, because each of grid and pack will try to resize the container according to it's rules, triggering the other one to reconfigure according to it's rules, and so on until the end of time.



    So, simply changing your call of .grid(...) to .pack(...) on the checkbuttons will fix that problem.



    My guess is that you intended to put the checkbuttons inside frame1. If that's the case, you need to specify frame1 as the master for the checkbuttons. For readability and ease of debugging I also recommend placing the call to grid on a separate line. With that, you can continue to use grid for the checkbuttons and pack for everything else.



    cb = Checkbutton(frame1, text=item.rstrip())
    cb.grid(row=count//10, column=count%10)





    share|improve this answer
























    • Many thanks Bryan, i understand better now. I started to use python since few days.. :). I got another issue on my code. I will create a new topic on Stack today or tomorrow. If is possible for you to take look please.I search how to get the values of each selected items.

      – Indi59
      Nov 15 '18 at 17:11
















    0














    The main problem is that you're mixing grid and pack in the same parent container. You are calling pack on frame1 but you are calling grid on the checkbuttons, and they both have a master or parent of self.



    That can't work, because each of grid and pack will try to resize the container according to it's rules, triggering the other one to reconfigure according to it's rules, and so on until the end of time.



    So, simply changing your call of .grid(...) to .pack(...) on the checkbuttons will fix that problem.



    My guess is that you intended to put the checkbuttons inside frame1. If that's the case, you need to specify frame1 as the master for the checkbuttons. For readability and ease of debugging I also recommend placing the call to grid on a separate line. With that, you can continue to use grid for the checkbuttons and pack for everything else.



    cb = Checkbutton(frame1, text=item.rstrip())
    cb.grid(row=count//10, column=count%10)





    share|improve this answer
























    • Many thanks Bryan, i understand better now. I started to use python since few days.. :). I got another issue on my code. I will create a new topic on Stack today or tomorrow. If is possible for you to take look please.I search how to get the values of each selected items.

      – Indi59
      Nov 15 '18 at 17:11














    0












    0








    0







    The main problem is that you're mixing grid and pack in the same parent container. You are calling pack on frame1 but you are calling grid on the checkbuttons, and they both have a master or parent of self.



    That can't work, because each of grid and pack will try to resize the container according to it's rules, triggering the other one to reconfigure according to it's rules, and so on until the end of time.



    So, simply changing your call of .grid(...) to .pack(...) on the checkbuttons will fix that problem.



    My guess is that you intended to put the checkbuttons inside frame1. If that's the case, you need to specify frame1 as the master for the checkbuttons. For readability and ease of debugging I also recommend placing the call to grid on a separate line. With that, you can continue to use grid for the checkbuttons and pack for everything else.



    cb = Checkbutton(frame1, text=item.rstrip())
    cb.grid(row=count//10, column=count%10)





    share|improve this answer













    The main problem is that you're mixing grid and pack in the same parent container. You are calling pack on frame1 but you are calling grid on the checkbuttons, and they both have a master or parent of self.



    That can't work, because each of grid and pack will try to resize the container according to it's rules, triggering the other one to reconfigure according to it's rules, and so on until the end of time.



    So, simply changing your call of .grid(...) to .pack(...) on the checkbuttons will fix that problem.



    My guess is that you intended to put the checkbuttons inside frame1. If that's the case, you need to specify frame1 as the master for the checkbuttons. For readability and ease of debugging I also recommend placing the call to grid on a separate line. With that, you can continue to use grid for the checkbuttons and pack for everything else.



    cb = Checkbutton(frame1, text=item.rstrip())
    cb.grid(row=count//10, column=count%10)






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 15 '18 at 17:01









    Bryan OakleyBryan Oakley

    215k22256418




    215k22256418













    • Many thanks Bryan, i understand better now. I started to use python since few days.. :). I got another issue on my code. I will create a new topic on Stack today or tomorrow. If is possible for you to take look please.I search how to get the values of each selected items.

      – Indi59
      Nov 15 '18 at 17:11



















    • Many thanks Bryan, i understand better now. I started to use python since few days.. :). I got another issue on my code. I will create a new topic on Stack today or tomorrow. If is possible for you to take look please.I search how to get the values of each selected items.

      – Indi59
      Nov 15 '18 at 17:11

















    Many thanks Bryan, i understand better now. I started to use python since few days.. :). I got another issue on my code. I will create a new topic on Stack today or tomorrow. If is possible for you to take look please.I search how to get the values of each selected items.

    – Indi59
    Nov 15 '18 at 17:11





    Many thanks Bryan, i understand better now. I started to use python since few days.. :). I got another issue on my code. I will create a new topic on Stack today or tomorrow. If is possible for you to take look please.I search how to get the values of each selected items.

    – Indi59
    Nov 15 '18 at 17:11













    0














    I posted the correct code:



    from tkinter import Tk, Frame, Menu, Checkbutton, Text, TOP, BOTH, X, N, LEFT, BooleanVar
    from tkinter.ttk import Frame, Label, Entry
    import glob

    class Example(Frame):

    def __init__(self):
    super().__init__()

    self.initUI()
    #self.display_srv()

    def initUI(self):

    self.master.title("Submenu")

    menubar = Menu(self.master)
    self.master.config(menu=menubar)

    fileMenu = Menu(menubar)

    submenu = Menu(fileMenu)
    submenu.add_command(label="lst1", command=self.onDisplay)
    submenu.add_command(label="lst2")
    submenu.add_command(label="lst3")
    fileMenu.add_cascade(label='Listing', menu=submenu, underline=0)

    fileMenu.add_separator()

    fileMenu.add_command(label="Exit", underline=0, command=self.onExit)
    menubar.add_cascade(label="File", underline=0, menu=fileMenu)
    def onDisplay(self):
    self.master.title("display it")
    self.pack(fill=BOTH, expand=True)
    frame1 = Frame(self)
    frame1.pack(fill=X)
    path = '/root/liste/*.txt'
    files=glob.glob(path)
    count = 0
    for file in files:
    with open(file, 'r') as lst_file:
    for item in lst_file:
    cb = Checkbutton(frame1, text=item.rstrip())
    cb.grid(row=count//10, column=count%10)
    count += 1

    def onClick(self):
    if self.var.get() == True:
    self.master.title("Checkbutton")
    else:
    self.master.title("")

    def onExit(self):

    self.quit()

    def main():

    root = Tk()
    root.geometry("850x550+300+300")
    app = Example()
    root.mainloop()

    if __name__ == '__main__':
    main()





    share|improve this answer




























      0














      I posted the correct code:



      from tkinter import Tk, Frame, Menu, Checkbutton, Text, TOP, BOTH, X, N, LEFT, BooleanVar
      from tkinter.ttk import Frame, Label, Entry
      import glob

      class Example(Frame):

      def __init__(self):
      super().__init__()

      self.initUI()
      #self.display_srv()

      def initUI(self):

      self.master.title("Submenu")

      menubar = Menu(self.master)
      self.master.config(menu=menubar)

      fileMenu = Menu(menubar)

      submenu = Menu(fileMenu)
      submenu.add_command(label="lst1", command=self.onDisplay)
      submenu.add_command(label="lst2")
      submenu.add_command(label="lst3")
      fileMenu.add_cascade(label='Listing', menu=submenu, underline=0)

      fileMenu.add_separator()

      fileMenu.add_command(label="Exit", underline=0, command=self.onExit)
      menubar.add_cascade(label="File", underline=0, menu=fileMenu)
      def onDisplay(self):
      self.master.title("display it")
      self.pack(fill=BOTH, expand=True)
      frame1 = Frame(self)
      frame1.pack(fill=X)
      path = '/root/liste/*.txt'
      files=glob.glob(path)
      count = 0
      for file in files:
      with open(file, 'r') as lst_file:
      for item in lst_file:
      cb = Checkbutton(frame1, text=item.rstrip())
      cb.grid(row=count//10, column=count%10)
      count += 1

      def onClick(self):
      if self.var.get() == True:
      self.master.title("Checkbutton")
      else:
      self.master.title("")

      def onExit(self):

      self.quit()

      def main():

      root = Tk()
      root.geometry("850x550+300+300")
      app = Example()
      root.mainloop()

      if __name__ == '__main__':
      main()





      share|improve this answer


























        0












        0








        0







        I posted the correct code:



        from tkinter import Tk, Frame, Menu, Checkbutton, Text, TOP, BOTH, X, N, LEFT, BooleanVar
        from tkinter.ttk import Frame, Label, Entry
        import glob

        class Example(Frame):

        def __init__(self):
        super().__init__()

        self.initUI()
        #self.display_srv()

        def initUI(self):

        self.master.title("Submenu")

        menubar = Menu(self.master)
        self.master.config(menu=menubar)

        fileMenu = Menu(menubar)

        submenu = Menu(fileMenu)
        submenu.add_command(label="lst1", command=self.onDisplay)
        submenu.add_command(label="lst2")
        submenu.add_command(label="lst3")
        fileMenu.add_cascade(label='Listing', menu=submenu, underline=0)

        fileMenu.add_separator()

        fileMenu.add_command(label="Exit", underline=0, command=self.onExit)
        menubar.add_cascade(label="File", underline=0, menu=fileMenu)
        def onDisplay(self):
        self.master.title("display it")
        self.pack(fill=BOTH, expand=True)
        frame1 = Frame(self)
        frame1.pack(fill=X)
        path = '/root/liste/*.txt'
        files=glob.glob(path)
        count = 0
        for file in files:
        with open(file, 'r') as lst_file:
        for item in lst_file:
        cb = Checkbutton(frame1, text=item.rstrip())
        cb.grid(row=count//10, column=count%10)
        count += 1

        def onClick(self):
        if self.var.get() == True:
        self.master.title("Checkbutton")
        else:
        self.master.title("")

        def onExit(self):

        self.quit()

        def main():

        root = Tk()
        root.geometry("850x550+300+300")
        app = Example()
        root.mainloop()

        if __name__ == '__main__':
        main()





        share|improve this answer













        I posted the correct code:



        from tkinter import Tk, Frame, Menu, Checkbutton, Text, TOP, BOTH, X, N, LEFT, BooleanVar
        from tkinter.ttk import Frame, Label, Entry
        import glob

        class Example(Frame):

        def __init__(self):
        super().__init__()

        self.initUI()
        #self.display_srv()

        def initUI(self):

        self.master.title("Submenu")

        menubar = Menu(self.master)
        self.master.config(menu=menubar)

        fileMenu = Menu(menubar)

        submenu = Menu(fileMenu)
        submenu.add_command(label="lst1", command=self.onDisplay)
        submenu.add_command(label="lst2")
        submenu.add_command(label="lst3")
        fileMenu.add_cascade(label='Listing', menu=submenu, underline=0)

        fileMenu.add_separator()

        fileMenu.add_command(label="Exit", underline=0, command=self.onExit)
        menubar.add_cascade(label="File", underline=0, menu=fileMenu)
        def onDisplay(self):
        self.master.title("display it")
        self.pack(fill=BOTH, expand=True)
        frame1 = Frame(self)
        frame1.pack(fill=X)
        path = '/root/liste/*.txt'
        files=glob.glob(path)
        count = 0
        for file in files:
        with open(file, 'r') as lst_file:
        for item in lst_file:
        cb = Checkbutton(frame1, text=item.rstrip())
        cb.grid(row=count//10, column=count%10)
        count += 1

        def onClick(self):
        if self.var.get() == True:
        self.master.title("Checkbutton")
        else:
        self.master.title("")

        def onExit(self):

        self.quit()

        def main():

        root = Tk()
        root.geometry("850x550+300+300")
        app = Example()
        root.mainloop()

        if __name__ == '__main__':
        main()






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 '18 at 17:16









        Indi59Indi59

        526




        526






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53322791%2ftkinter-display-new-frame-from-menu%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()