tkinter display frame on click










0















I'm trying to display/include a function display_srv on a click from the menu bar command and get values of each checkbox selected with the button Done



import tkinter as tk
import glob
from tkinter import *

def frame_1():
print("frame 1!")


The function I tried to display in the frame:



def display_srv():
frame_1 = root.LabelFrame(root, text="Liste Serveurs")
frame_1.grid(row=0, sticky='ew', padx=20, pady=20, ipadx=5, ipady=5)
path = '/home/lst/*.txt'
files=glob.glob(path)
count = 0
for file in files:
with open(file, 'r') as lst_file:
for item in lst_file:
lng = root.Checkbutton(frame_1, variable = item, text=item.rstrip()).grid(row=count//10, column=count%10)
count += 1


Text file value:



item1
item2
item3
...
item100


The function to get values:



def getvalue():
print(list(lng.values()))


The main script:



root = Tk()
menu = Menu(root)
root.geometry('700x500')
root.title("My menu")
root.config(menu=menu)
testpsimenu = Menu(menu)
menu.add_cascade(label="Test Menu", menu=testpsimenu, font=("Arial", 12))
testpsimenu.add_command(label="Select 1", font=("Arial", 10), command=frame_1)
testpsimenu.add_separator()
testpsimenu.add_command(label="Select 2", font=("Arial", 10), command=display_srv)

psimenu = Menu(menu)
menu.add_cascade(label="PSI Real", menu=psimenu, font=("Arial", 12))
psimenu.add_command(label="Select 1", font=("Arial", 10), command=frame_1)
psimenu.add_separator()
psimenu.add_command(label="Select 2", font=("Arial", 10), command=frame_1)

exitmenu = Menu(menu)
menu.add_cascade(label="Exit", menu=exitmenu, font=("Arial", 12))
exitmenu.add_command(label="Exit", command=root.quit, font=("Arial", 10))

Button(root, text='Done', font=("Arial", 12), command=getvalue).pack(side=RIGHT)

mainloop()


This is the error, when I click on Select2 from the menu testpsi:



Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib64/python3.6/tkinter/__init__.py", line 1702, in __call__
return self.func(*args)
File "./test_menu_7.py", line 13, in display_srv
frame_1 = root.LabelFrame(root, text="Liste Serveurs")
File "/usr/lib64/python3.6/tkinter/__init__.py", line 2098, in __getattr__
return getattr(self.tk, attr)
AttributeError: '_tkinter.tkapp' object has no attribute 'LabelFrame'


Many thanks for your help...










share|improve this question
























  • What is the question?

    – Black Thunder
    Nov 14 '18 at 16:50











  • how can i dispplay the function "display_srv" when i click on a button from menu bar

    – Indi59
    Nov 14 '18 at 17:19











  • This root.LabelFrame should read tk.LabelFrame

    – stovfl
    Nov 14 '18 at 17:53















0















I'm trying to display/include a function display_srv on a click from the menu bar command and get values of each checkbox selected with the button Done



import tkinter as tk
import glob
from tkinter import *

def frame_1():
print("frame 1!")


The function I tried to display in the frame:



def display_srv():
frame_1 = root.LabelFrame(root, text="Liste Serveurs")
frame_1.grid(row=0, sticky='ew', padx=20, pady=20, ipadx=5, ipady=5)
path = '/home/lst/*.txt'
files=glob.glob(path)
count = 0
for file in files:
with open(file, 'r') as lst_file:
for item in lst_file:
lng = root.Checkbutton(frame_1, variable = item, text=item.rstrip()).grid(row=count//10, column=count%10)
count += 1


Text file value:



item1
item2
item3
...
item100


The function to get values:



def getvalue():
print(list(lng.values()))


The main script:



root = Tk()
menu = Menu(root)
root.geometry('700x500')
root.title("My menu")
root.config(menu=menu)
testpsimenu = Menu(menu)
menu.add_cascade(label="Test Menu", menu=testpsimenu, font=("Arial", 12))
testpsimenu.add_command(label="Select 1", font=("Arial", 10), command=frame_1)
testpsimenu.add_separator()
testpsimenu.add_command(label="Select 2", font=("Arial", 10), command=display_srv)

psimenu = Menu(menu)
menu.add_cascade(label="PSI Real", menu=psimenu, font=("Arial", 12))
psimenu.add_command(label="Select 1", font=("Arial", 10), command=frame_1)
psimenu.add_separator()
psimenu.add_command(label="Select 2", font=("Arial", 10), command=frame_1)

exitmenu = Menu(menu)
menu.add_cascade(label="Exit", menu=exitmenu, font=("Arial", 12))
exitmenu.add_command(label="Exit", command=root.quit, font=("Arial", 10))

Button(root, text='Done', font=("Arial", 12), command=getvalue).pack(side=RIGHT)

mainloop()


This is the error, when I click on Select2 from the menu testpsi:



Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib64/python3.6/tkinter/__init__.py", line 1702, in __call__
return self.func(*args)
File "./test_menu_7.py", line 13, in display_srv
frame_1 = root.LabelFrame(root, text="Liste Serveurs")
File "/usr/lib64/python3.6/tkinter/__init__.py", line 2098, in __getattr__
return getattr(self.tk, attr)
AttributeError: '_tkinter.tkapp' object has no attribute 'LabelFrame'


Many thanks for your help...










share|improve this question
























  • What is the question?

    – Black Thunder
    Nov 14 '18 at 16:50











  • how can i dispplay the function "display_srv" when i click on a button from menu bar

    – Indi59
    Nov 14 '18 at 17:19











  • This root.LabelFrame should read tk.LabelFrame

    – stovfl
    Nov 14 '18 at 17:53













0












0








0








I'm trying to display/include a function display_srv on a click from the menu bar command and get values of each checkbox selected with the button Done



import tkinter as tk
import glob
from tkinter import *

def frame_1():
print("frame 1!")


The function I tried to display in the frame:



def display_srv():
frame_1 = root.LabelFrame(root, text="Liste Serveurs")
frame_1.grid(row=0, sticky='ew', padx=20, pady=20, ipadx=5, ipady=5)
path = '/home/lst/*.txt'
files=glob.glob(path)
count = 0
for file in files:
with open(file, 'r') as lst_file:
for item in lst_file:
lng = root.Checkbutton(frame_1, variable = item, text=item.rstrip()).grid(row=count//10, column=count%10)
count += 1


Text file value:



item1
item2
item3
...
item100


The function to get values:



def getvalue():
print(list(lng.values()))


The main script:



root = Tk()
menu = Menu(root)
root.geometry('700x500')
root.title("My menu")
root.config(menu=menu)
testpsimenu = Menu(menu)
menu.add_cascade(label="Test Menu", menu=testpsimenu, font=("Arial", 12))
testpsimenu.add_command(label="Select 1", font=("Arial", 10), command=frame_1)
testpsimenu.add_separator()
testpsimenu.add_command(label="Select 2", font=("Arial", 10), command=display_srv)

psimenu = Menu(menu)
menu.add_cascade(label="PSI Real", menu=psimenu, font=("Arial", 12))
psimenu.add_command(label="Select 1", font=("Arial", 10), command=frame_1)
psimenu.add_separator()
psimenu.add_command(label="Select 2", font=("Arial", 10), command=frame_1)

exitmenu = Menu(menu)
menu.add_cascade(label="Exit", menu=exitmenu, font=("Arial", 12))
exitmenu.add_command(label="Exit", command=root.quit, font=("Arial", 10))

Button(root, text='Done', font=("Arial", 12), command=getvalue).pack(side=RIGHT)

mainloop()


This is the error, when I click on Select2 from the menu testpsi:



Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib64/python3.6/tkinter/__init__.py", line 1702, in __call__
return self.func(*args)
File "./test_menu_7.py", line 13, in display_srv
frame_1 = root.LabelFrame(root, text="Liste Serveurs")
File "/usr/lib64/python3.6/tkinter/__init__.py", line 2098, in __getattr__
return getattr(self.tk, attr)
AttributeError: '_tkinter.tkapp' object has no attribute 'LabelFrame'


Many thanks for your help...










share|improve this question
















I'm trying to display/include a function display_srv on a click from the menu bar command and get values of each checkbox selected with the button Done



import tkinter as tk
import glob
from tkinter import *

def frame_1():
print("frame 1!")


The function I tried to display in the frame:



def display_srv():
frame_1 = root.LabelFrame(root, text="Liste Serveurs")
frame_1.grid(row=0, sticky='ew', padx=20, pady=20, ipadx=5, ipady=5)
path = '/home/lst/*.txt'
files=glob.glob(path)
count = 0
for file in files:
with open(file, 'r') as lst_file:
for item in lst_file:
lng = root.Checkbutton(frame_1, variable = item, text=item.rstrip()).grid(row=count//10, column=count%10)
count += 1


Text file value:



item1
item2
item3
...
item100


The function to get values:



def getvalue():
print(list(lng.values()))


The main script:



root = Tk()
menu = Menu(root)
root.geometry('700x500')
root.title("My menu")
root.config(menu=menu)
testpsimenu = Menu(menu)
menu.add_cascade(label="Test Menu", menu=testpsimenu, font=("Arial", 12))
testpsimenu.add_command(label="Select 1", font=("Arial", 10), command=frame_1)
testpsimenu.add_separator()
testpsimenu.add_command(label="Select 2", font=("Arial", 10), command=display_srv)

psimenu = Menu(menu)
menu.add_cascade(label="PSI Real", menu=psimenu, font=("Arial", 12))
psimenu.add_command(label="Select 1", font=("Arial", 10), command=frame_1)
psimenu.add_separator()
psimenu.add_command(label="Select 2", font=("Arial", 10), command=frame_1)

exitmenu = Menu(menu)
menu.add_cascade(label="Exit", menu=exitmenu, font=("Arial", 12))
exitmenu.add_command(label="Exit", command=root.quit, font=("Arial", 10))

Button(root, text='Done', font=("Arial", 12), command=getvalue).pack(side=RIGHT)

mainloop()


This is the error, when I click on Select2 from the menu testpsi:



Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib64/python3.6/tkinter/__init__.py", line 1702, in __call__
return self.func(*args)
File "./test_menu_7.py", line 13, in display_srv
frame_1 = root.LabelFrame(root, text="Liste Serveurs")
File "/usr/lib64/python3.6/tkinter/__init__.py", line 2098, in __getattr__
return getattr(self.tk, attr)
AttributeError: '_tkinter.tkapp' object has no attribute 'LabelFrame'


Many thanks for your help...







python checkbox tkinter frame






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 16:50









Black Thunder

2,2653932




2,2653932










asked Nov 14 '18 at 16:46









Indi59Indi59

526




526












  • What is the question?

    – Black Thunder
    Nov 14 '18 at 16:50











  • how can i dispplay the function "display_srv" when i click on a button from menu bar

    – Indi59
    Nov 14 '18 at 17:19











  • This root.LabelFrame should read tk.LabelFrame

    – stovfl
    Nov 14 '18 at 17:53

















  • What is the question?

    – Black Thunder
    Nov 14 '18 at 16:50











  • how can i dispplay the function "display_srv" when i click on a button from menu bar

    – Indi59
    Nov 14 '18 at 17:19











  • This root.LabelFrame should read tk.LabelFrame

    – stovfl
    Nov 14 '18 at 17:53
















What is the question?

– Black Thunder
Nov 14 '18 at 16:50





What is the question?

– Black Thunder
Nov 14 '18 at 16:50













how can i dispplay the function "display_srv" when i click on a button from menu bar

– Indi59
Nov 14 '18 at 17:19





how can i dispplay the function "display_srv" when i click on a button from menu bar

– Indi59
Nov 14 '18 at 17:19













This root.LabelFrame should read tk.LabelFrame

– stovfl
Nov 14 '18 at 17:53





This root.LabelFrame should read tk.LabelFrame

– stovfl
Nov 14 '18 at 17:53












1 Answer
1






active

oldest

votes


















0














I can see 2 problems so far.



  1. You need to use the tk. prefix on your widgets and not root.

Change these:



root.LabelFrame
root.Checkbutton


To these:



tk.LabelFrame
tk.Checkbutton


  1. You need to define lng as a global variable so it can be used in your getvalue() function.

Add this line global lng to the top of display_srv() like this:



def display_srv():
global lng


Let me know if you have any questions.






share|improve this answer























  • I can display the list in the frame, many thanks

    – Indi59
    Nov 15 '18 at 7:35










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%2f53305062%2ftkinter-display-frame-on-click%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I can see 2 problems so far.



  1. You need to use the tk. prefix on your widgets and not root.

Change these:



root.LabelFrame
root.Checkbutton


To these:



tk.LabelFrame
tk.Checkbutton


  1. You need to define lng as a global variable so it can be used in your getvalue() function.

Add this line global lng to the top of display_srv() like this:



def display_srv():
global lng


Let me know if you have any questions.






share|improve this answer























  • I can display the list in the frame, many thanks

    – Indi59
    Nov 15 '18 at 7:35















0














I can see 2 problems so far.



  1. You need to use the tk. prefix on your widgets and not root.

Change these:



root.LabelFrame
root.Checkbutton


To these:



tk.LabelFrame
tk.Checkbutton


  1. You need to define lng as a global variable so it can be used in your getvalue() function.

Add this line global lng to the top of display_srv() like this:



def display_srv():
global lng


Let me know if you have any questions.






share|improve this answer























  • I can display the list in the frame, many thanks

    – Indi59
    Nov 15 '18 at 7:35













0












0








0







I can see 2 problems so far.



  1. You need to use the tk. prefix on your widgets and not root.

Change these:



root.LabelFrame
root.Checkbutton


To these:



tk.LabelFrame
tk.Checkbutton


  1. You need to define lng as a global variable so it can be used in your getvalue() function.

Add this line global lng to the top of display_srv() like this:



def display_srv():
global lng


Let me know if you have any questions.






share|improve this answer













I can see 2 problems so far.



  1. You need to use the tk. prefix on your widgets and not root.

Change these:



root.LabelFrame
root.Checkbutton


To these:



tk.LabelFrame
tk.Checkbutton


  1. You need to define lng as a global variable so it can be used in your getvalue() function.

Add this line global lng to the top of display_srv() like this:



def display_srv():
global lng


Let me know if you have any questions.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 '18 at 21:01









Mike - SMTMike - SMT

9,70121435




9,70121435












  • I can display the list in the frame, many thanks

    – Indi59
    Nov 15 '18 at 7:35

















  • I can display the list in the frame, many thanks

    – Indi59
    Nov 15 '18 at 7:35
















I can display the list in the frame, many thanks

– Indi59
Nov 15 '18 at 7:35





I can display the list in the frame, many thanks

– Indi59
Nov 15 '18 at 7:35



















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%2f53305062%2ftkinter-display-frame-on-click%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







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo