Python Tkinter - How to put widgets from one class onto a window in another class
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have a window from the MainGUIApp class, and I have some widgets from another class that I want to place on this MainGUIApp class. How would this be done?
import tkinter as tk
from tkinter import ttk, Tk, Menu, Label, StringVar, OptionMenu, Entry, Button, messagebox, Canvas, HORIZONTAL, Text, END
class MainGUIApp(tk.Tk):
def __init__(self, window_title, window_width, window_length):
# Window settings
super(MainGUIApp, self).__init__()
self.title(window_title)
# get screen width and height
ws = self.winfo_screenwidth()
hs = self.winfo_screenheight()
# calculate position x, y
x = (ws / 2) - (window_width / 2)
y = (hs / 2) - (window_length / 2)
self.geometry('%dx%d+%d+%d' % (window_width, window_length, x, y))
self.current_directory = "C://Path"
self.current_company = "Test_Company"
self.top_panel = TopPanel.TopPanel(self, self.current_directory, self.current_company)
Where TopPanel class looks like this:
from tkinter import Tk
from tkinter import ttk, Tk
class TopPanel(tk.Tk):
def __init__(self, parent_frame, current_directory, current_company):
super(parent_frame, self).__init__()
self.current_directory = current_directory
self.show_current_directory()
def show_current_directory(self):
# Have a text for current directory, pad y by 20, and set anchor to w (west)
if self.current_directory is None:
current_directory_text = Label(self,
text="Current Directory:" + ' '
+ "No directory assigned",
font=("Helvetica", 12), anchor='w', pady=20)
else:
current_directory_text = Label(self,
text="Current Directory:" + ' '
+ self.current_directory,
font=("Helvetica", 12), anchor='w', pady=20)
current_directory_text.grid(row=0, sticky="w")
But the problem is: TopPanel opens up as a new window. I want TopPanel components to be a part of MainGuiApp.
python tkinter
|
show 1 more comment
I have a window from the MainGUIApp class, and I have some widgets from another class that I want to place on this MainGUIApp class. How would this be done?
import tkinter as tk
from tkinter import ttk, Tk, Menu, Label, StringVar, OptionMenu, Entry, Button, messagebox, Canvas, HORIZONTAL, Text, END
class MainGUIApp(tk.Tk):
def __init__(self, window_title, window_width, window_length):
# Window settings
super(MainGUIApp, self).__init__()
self.title(window_title)
# get screen width and height
ws = self.winfo_screenwidth()
hs = self.winfo_screenheight()
# calculate position x, y
x = (ws / 2) - (window_width / 2)
y = (hs / 2) - (window_length / 2)
self.geometry('%dx%d+%d+%d' % (window_width, window_length, x, y))
self.current_directory = "C://Path"
self.current_company = "Test_Company"
self.top_panel = TopPanel.TopPanel(self, self.current_directory, self.current_company)
Where TopPanel class looks like this:
from tkinter import Tk
from tkinter import ttk, Tk
class TopPanel(tk.Tk):
def __init__(self, parent_frame, current_directory, current_company):
super(parent_frame, self).__init__()
self.current_directory = current_directory
self.show_current_directory()
def show_current_directory(self):
# Have a text for current directory, pad y by 20, and set anchor to w (west)
if self.current_directory is None:
current_directory_text = Label(self,
text="Current Directory:" + ' '
+ "No directory assigned",
font=("Helvetica", 12), anchor='w', pady=20)
else:
current_directory_text = Label(self,
text="Current Directory:" + ' '
+ self.current_directory,
font=("Helvetica", 12), anchor='w', pady=20)
current_directory_text.grid(row=0, sticky="w")
But the problem is: TopPanel opens up as a new window. I want TopPanel components to be a part of MainGuiApp.
python tkinter
What is the line you are using to import Tkinter? Not on windows, butimport Tkinter
and inheriting fromTkinter.Tk
is what works on linux.
– jackw11111
Nov 24 '18 at 23:07
@jackw11111 I've added the import lines to my code. Also I am using windows.
– Theo
Nov 24 '18 at 23:16
When you useimport tkinter as tk
as the only import statement, see if inheriting fromtk.Tk
works.
– jackw11111
Nov 24 '18 at 23:21
Soclass TopPanel(Tk.tk)
becomesclass TopPanel(tk.Tk)
and the same change forMainGuiApp
.
– jackw11111
Nov 24 '18 at 23:25
@jackw11111 this works! but it creates a new window for TopPanel. How can I have the contents of TopPanel on MainGuiApp
– Theo
Nov 24 '18 at 23:26
|
show 1 more comment
I have a window from the MainGUIApp class, and I have some widgets from another class that I want to place on this MainGUIApp class. How would this be done?
import tkinter as tk
from tkinter import ttk, Tk, Menu, Label, StringVar, OptionMenu, Entry, Button, messagebox, Canvas, HORIZONTAL, Text, END
class MainGUIApp(tk.Tk):
def __init__(self, window_title, window_width, window_length):
# Window settings
super(MainGUIApp, self).__init__()
self.title(window_title)
# get screen width and height
ws = self.winfo_screenwidth()
hs = self.winfo_screenheight()
# calculate position x, y
x = (ws / 2) - (window_width / 2)
y = (hs / 2) - (window_length / 2)
self.geometry('%dx%d+%d+%d' % (window_width, window_length, x, y))
self.current_directory = "C://Path"
self.current_company = "Test_Company"
self.top_panel = TopPanel.TopPanel(self, self.current_directory, self.current_company)
Where TopPanel class looks like this:
from tkinter import Tk
from tkinter import ttk, Tk
class TopPanel(tk.Tk):
def __init__(self, parent_frame, current_directory, current_company):
super(parent_frame, self).__init__()
self.current_directory = current_directory
self.show_current_directory()
def show_current_directory(self):
# Have a text for current directory, pad y by 20, and set anchor to w (west)
if self.current_directory is None:
current_directory_text = Label(self,
text="Current Directory:" + ' '
+ "No directory assigned",
font=("Helvetica", 12), anchor='w', pady=20)
else:
current_directory_text = Label(self,
text="Current Directory:" + ' '
+ self.current_directory,
font=("Helvetica", 12), anchor='w', pady=20)
current_directory_text.grid(row=0, sticky="w")
But the problem is: TopPanel opens up as a new window. I want TopPanel components to be a part of MainGuiApp.
python tkinter
I have a window from the MainGUIApp class, and I have some widgets from another class that I want to place on this MainGUIApp class. How would this be done?
import tkinter as tk
from tkinter import ttk, Tk, Menu, Label, StringVar, OptionMenu, Entry, Button, messagebox, Canvas, HORIZONTAL, Text, END
class MainGUIApp(tk.Tk):
def __init__(self, window_title, window_width, window_length):
# Window settings
super(MainGUIApp, self).__init__()
self.title(window_title)
# get screen width and height
ws = self.winfo_screenwidth()
hs = self.winfo_screenheight()
# calculate position x, y
x = (ws / 2) - (window_width / 2)
y = (hs / 2) - (window_length / 2)
self.geometry('%dx%d+%d+%d' % (window_width, window_length, x, y))
self.current_directory = "C://Path"
self.current_company = "Test_Company"
self.top_panel = TopPanel.TopPanel(self, self.current_directory, self.current_company)
Where TopPanel class looks like this:
from tkinter import Tk
from tkinter import ttk, Tk
class TopPanel(tk.Tk):
def __init__(self, parent_frame, current_directory, current_company):
super(parent_frame, self).__init__()
self.current_directory = current_directory
self.show_current_directory()
def show_current_directory(self):
# Have a text for current directory, pad y by 20, and set anchor to w (west)
if self.current_directory is None:
current_directory_text = Label(self,
text="Current Directory:" + ' '
+ "No directory assigned",
font=("Helvetica", 12), anchor='w', pady=20)
else:
current_directory_text = Label(self,
text="Current Directory:" + ' '
+ self.current_directory,
font=("Helvetica", 12), anchor='w', pady=20)
current_directory_text.grid(row=0, sticky="w")
But the problem is: TopPanel opens up as a new window. I want TopPanel components to be a part of MainGuiApp.
python tkinter
python tkinter
edited Nov 24 '18 at 23:48
Theo
asked Nov 24 '18 at 22:41
TheoTheo
377316
377316
What is the line you are using to import Tkinter? Not on windows, butimport Tkinter
and inheriting fromTkinter.Tk
is what works on linux.
– jackw11111
Nov 24 '18 at 23:07
@jackw11111 I've added the import lines to my code. Also I am using windows.
– Theo
Nov 24 '18 at 23:16
When you useimport tkinter as tk
as the only import statement, see if inheriting fromtk.Tk
works.
– jackw11111
Nov 24 '18 at 23:21
Soclass TopPanel(Tk.tk)
becomesclass TopPanel(tk.Tk)
and the same change forMainGuiApp
.
– jackw11111
Nov 24 '18 at 23:25
@jackw11111 this works! but it creates a new window for TopPanel. How can I have the contents of TopPanel on MainGuiApp
– Theo
Nov 24 '18 at 23:26
|
show 1 more comment
What is the line you are using to import Tkinter? Not on windows, butimport Tkinter
and inheriting fromTkinter.Tk
is what works on linux.
– jackw11111
Nov 24 '18 at 23:07
@jackw11111 I've added the import lines to my code. Also I am using windows.
– Theo
Nov 24 '18 at 23:16
When you useimport tkinter as tk
as the only import statement, see if inheriting fromtk.Tk
works.
– jackw11111
Nov 24 '18 at 23:21
Soclass TopPanel(Tk.tk)
becomesclass TopPanel(tk.Tk)
and the same change forMainGuiApp
.
– jackw11111
Nov 24 '18 at 23:25
@jackw11111 this works! but it creates a new window for TopPanel. How can I have the contents of TopPanel on MainGuiApp
– Theo
Nov 24 '18 at 23:26
What is the line you are using to import Tkinter? Not on windows, but
import Tkinter
and inheriting from Tkinter.Tk
is what works on linux.– jackw11111
Nov 24 '18 at 23:07
What is the line you are using to import Tkinter? Not on windows, but
import Tkinter
and inheriting from Tkinter.Tk
is what works on linux.– jackw11111
Nov 24 '18 at 23:07
@jackw11111 I've added the import lines to my code. Also I am using windows.
– Theo
Nov 24 '18 at 23:16
@jackw11111 I've added the import lines to my code. Also I am using windows.
– Theo
Nov 24 '18 at 23:16
When you use
import tkinter as tk
as the only import statement, see if inheriting from tk.Tk
works.– jackw11111
Nov 24 '18 at 23:21
When you use
import tkinter as tk
as the only import statement, see if inheriting from tk.Tk
works.– jackw11111
Nov 24 '18 at 23:21
So
class TopPanel(Tk.tk)
becomes class TopPanel(tk.Tk)
and the same change for MainGuiApp
.– jackw11111
Nov 24 '18 at 23:25
So
class TopPanel(Tk.tk)
becomes class TopPanel(tk.Tk)
and the same change for MainGuiApp
.– jackw11111
Nov 24 '18 at 23:25
@jackw11111 this works! but it creates a new window for TopPanel. How can I have the contents of TopPanel on MainGuiApp
– Theo
Nov 24 '18 at 23:26
@jackw11111 this works! but it creates a new window for TopPanel. How can I have the contents of TopPanel on MainGuiApp
– Theo
Nov 24 '18 at 23:26
|
show 1 more comment
1 Answer
1
active
oldest
votes
In short your TopPanel
needs to inherit from tk.Frame
:
class TopPanel(tk.Frame):
Change the line so that you are initializing tk.Frame
with:
super(TopPanel, self).__init__()
And when initializing the TopPanel
instance, be sure to position it with:
self.top_panel.grid(row=0, column=0, sticky="nsew")
import tkinter as tk
from tkinter import ttk, Tk, Menu, Label, StringVar, OptionMenu, Entry, Button, messagebox, Canvas, HORIZONTAL, Text, END
class MainGUIApp(tk.Tk):
def __init__(self, window_title, window_width, window_length):
# Window settings
super(MainGUIApp, self).__init__()
self.title(window_title)
# get screen width and height
ws = self.winfo_screenwidth()
hs = self.winfo_screenheight()
# calculate position x, y
x = (ws / 2) - (window_width / 2)
y = (hs / 2) - (window_length / 2)
self.geometry('%dx%d+%d+%d' % (window_width, window_length, x, y))
self.current_directory = "C://Path"
self.current_company = "Test_Company"
self.top_panel = TopPanel(self, self.current_directory, self.current_company)
self.top_panel.grid(row=0, column=0, sticky="nsew")
from tkinter import Tk
from tkinter import ttk, Tk
class TopPanel(tk.Frame):
def __init__(self, parent_frame, current_directory, current_company):
super(TopPanel, self).__init__()
self.current_directory = current_directory
self.show_current_directory()
def show_current_directory(self):
# Have a text for current directory, pad y by 20, and set anchor to w (west)
if self.current_directory is None:
current_directory_text = Label(self,
text="Current Directory:" + ' '
+ "No directory assigned",
font=("Helvetica", 12), anchor='w', pady=20)
else:
current_directory_text = Label(self,
text="Current Directory:" + ' '
+ self.current_directory,
font=("Helvetica", 12), anchor='w', pady=20)
current_directory_text.grid(row=0, sticky="w")
main = MainGUIApp("test", 500, 500)
main.mainloop()
1
If you are going to use code based on another answer, it might be good to mention that.
– Bryan Oakley
Nov 25 '18 at 0:40
Exactly what I was looking for, thank you very much!!
– Theo
Nov 25 '18 at 6:58
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53462979%2fpython-tkinter-how-to-put-widgets-from-one-class-onto-a-window-in-another-clas%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
In short your TopPanel
needs to inherit from tk.Frame
:
class TopPanel(tk.Frame):
Change the line so that you are initializing tk.Frame
with:
super(TopPanel, self).__init__()
And when initializing the TopPanel
instance, be sure to position it with:
self.top_panel.grid(row=0, column=0, sticky="nsew")
import tkinter as tk
from tkinter import ttk, Tk, Menu, Label, StringVar, OptionMenu, Entry, Button, messagebox, Canvas, HORIZONTAL, Text, END
class MainGUIApp(tk.Tk):
def __init__(self, window_title, window_width, window_length):
# Window settings
super(MainGUIApp, self).__init__()
self.title(window_title)
# get screen width and height
ws = self.winfo_screenwidth()
hs = self.winfo_screenheight()
# calculate position x, y
x = (ws / 2) - (window_width / 2)
y = (hs / 2) - (window_length / 2)
self.geometry('%dx%d+%d+%d' % (window_width, window_length, x, y))
self.current_directory = "C://Path"
self.current_company = "Test_Company"
self.top_panel = TopPanel(self, self.current_directory, self.current_company)
self.top_panel.grid(row=0, column=0, sticky="nsew")
from tkinter import Tk
from tkinter import ttk, Tk
class TopPanel(tk.Frame):
def __init__(self, parent_frame, current_directory, current_company):
super(TopPanel, self).__init__()
self.current_directory = current_directory
self.show_current_directory()
def show_current_directory(self):
# Have a text for current directory, pad y by 20, and set anchor to w (west)
if self.current_directory is None:
current_directory_text = Label(self,
text="Current Directory:" + ' '
+ "No directory assigned",
font=("Helvetica", 12), anchor='w', pady=20)
else:
current_directory_text = Label(self,
text="Current Directory:" + ' '
+ self.current_directory,
font=("Helvetica", 12), anchor='w', pady=20)
current_directory_text.grid(row=0, sticky="w")
main = MainGUIApp("test", 500, 500)
main.mainloop()
1
If you are going to use code based on another answer, it might be good to mention that.
– Bryan Oakley
Nov 25 '18 at 0:40
Exactly what I was looking for, thank you very much!!
– Theo
Nov 25 '18 at 6:58
add a comment |
In short your TopPanel
needs to inherit from tk.Frame
:
class TopPanel(tk.Frame):
Change the line so that you are initializing tk.Frame
with:
super(TopPanel, self).__init__()
And when initializing the TopPanel
instance, be sure to position it with:
self.top_panel.grid(row=0, column=0, sticky="nsew")
import tkinter as tk
from tkinter import ttk, Tk, Menu, Label, StringVar, OptionMenu, Entry, Button, messagebox, Canvas, HORIZONTAL, Text, END
class MainGUIApp(tk.Tk):
def __init__(self, window_title, window_width, window_length):
# Window settings
super(MainGUIApp, self).__init__()
self.title(window_title)
# get screen width and height
ws = self.winfo_screenwidth()
hs = self.winfo_screenheight()
# calculate position x, y
x = (ws / 2) - (window_width / 2)
y = (hs / 2) - (window_length / 2)
self.geometry('%dx%d+%d+%d' % (window_width, window_length, x, y))
self.current_directory = "C://Path"
self.current_company = "Test_Company"
self.top_panel = TopPanel(self, self.current_directory, self.current_company)
self.top_panel.grid(row=0, column=0, sticky="nsew")
from tkinter import Tk
from tkinter import ttk, Tk
class TopPanel(tk.Frame):
def __init__(self, parent_frame, current_directory, current_company):
super(TopPanel, self).__init__()
self.current_directory = current_directory
self.show_current_directory()
def show_current_directory(self):
# Have a text for current directory, pad y by 20, and set anchor to w (west)
if self.current_directory is None:
current_directory_text = Label(self,
text="Current Directory:" + ' '
+ "No directory assigned",
font=("Helvetica", 12), anchor='w', pady=20)
else:
current_directory_text = Label(self,
text="Current Directory:" + ' '
+ self.current_directory,
font=("Helvetica", 12), anchor='w', pady=20)
current_directory_text.grid(row=0, sticky="w")
main = MainGUIApp("test", 500, 500)
main.mainloop()
1
If you are going to use code based on another answer, it might be good to mention that.
– Bryan Oakley
Nov 25 '18 at 0:40
Exactly what I was looking for, thank you very much!!
– Theo
Nov 25 '18 at 6:58
add a comment |
In short your TopPanel
needs to inherit from tk.Frame
:
class TopPanel(tk.Frame):
Change the line so that you are initializing tk.Frame
with:
super(TopPanel, self).__init__()
And when initializing the TopPanel
instance, be sure to position it with:
self.top_panel.grid(row=0, column=0, sticky="nsew")
import tkinter as tk
from tkinter import ttk, Tk, Menu, Label, StringVar, OptionMenu, Entry, Button, messagebox, Canvas, HORIZONTAL, Text, END
class MainGUIApp(tk.Tk):
def __init__(self, window_title, window_width, window_length):
# Window settings
super(MainGUIApp, self).__init__()
self.title(window_title)
# get screen width and height
ws = self.winfo_screenwidth()
hs = self.winfo_screenheight()
# calculate position x, y
x = (ws / 2) - (window_width / 2)
y = (hs / 2) - (window_length / 2)
self.geometry('%dx%d+%d+%d' % (window_width, window_length, x, y))
self.current_directory = "C://Path"
self.current_company = "Test_Company"
self.top_panel = TopPanel(self, self.current_directory, self.current_company)
self.top_panel.grid(row=0, column=0, sticky="nsew")
from tkinter import Tk
from tkinter import ttk, Tk
class TopPanel(tk.Frame):
def __init__(self, parent_frame, current_directory, current_company):
super(TopPanel, self).__init__()
self.current_directory = current_directory
self.show_current_directory()
def show_current_directory(self):
# Have a text for current directory, pad y by 20, and set anchor to w (west)
if self.current_directory is None:
current_directory_text = Label(self,
text="Current Directory:" + ' '
+ "No directory assigned",
font=("Helvetica", 12), anchor='w', pady=20)
else:
current_directory_text = Label(self,
text="Current Directory:" + ' '
+ self.current_directory,
font=("Helvetica", 12), anchor='w', pady=20)
current_directory_text.grid(row=0, sticky="w")
main = MainGUIApp("test", 500, 500)
main.mainloop()
In short your TopPanel
needs to inherit from tk.Frame
:
class TopPanel(tk.Frame):
Change the line so that you are initializing tk.Frame
with:
super(TopPanel, self).__init__()
And when initializing the TopPanel
instance, be sure to position it with:
self.top_panel.grid(row=0, column=0, sticky="nsew")
import tkinter as tk
from tkinter import ttk, Tk, Menu, Label, StringVar, OptionMenu, Entry, Button, messagebox, Canvas, HORIZONTAL, Text, END
class MainGUIApp(tk.Tk):
def __init__(self, window_title, window_width, window_length):
# Window settings
super(MainGUIApp, self).__init__()
self.title(window_title)
# get screen width and height
ws = self.winfo_screenwidth()
hs = self.winfo_screenheight()
# calculate position x, y
x = (ws / 2) - (window_width / 2)
y = (hs / 2) - (window_length / 2)
self.geometry('%dx%d+%d+%d' % (window_width, window_length, x, y))
self.current_directory = "C://Path"
self.current_company = "Test_Company"
self.top_panel = TopPanel(self, self.current_directory, self.current_company)
self.top_panel.grid(row=0, column=0, sticky="nsew")
from tkinter import Tk
from tkinter import ttk, Tk
class TopPanel(tk.Frame):
def __init__(self, parent_frame, current_directory, current_company):
super(TopPanel, self).__init__()
self.current_directory = current_directory
self.show_current_directory()
def show_current_directory(self):
# Have a text for current directory, pad y by 20, and set anchor to w (west)
if self.current_directory is None:
current_directory_text = Label(self,
text="Current Directory:" + ' '
+ "No directory assigned",
font=("Helvetica", 12), anchor='w', pady=20)
else:
current_directory_text = Label(self,
text="Current Directory:" + ' '
+ self.current_directory,
font=("Helvetica", 12), anchor='w', pady=20)
current_directory_text.grid(row=0, sticky="w")
main = MainGUIApp("test", 500, 500)
main.mainloop()
edited Dec 7 '18 at 11:00
answered Nov 25 '18 at 0:34
jackw11111jackw11111
393619
393619
1
If you are going to use code based on another answer, it might be good to mention that.
– Bryan Oakley
Nov 25 '18 at 0:40
Exactly what I was looking for, thank you very much!!
– Theo
Nov 25 '18 at 6:58
add a comment |
1
If you are going to use code based on another answer, it might be good to mention that.
– Bryan Oakley
Nov 25 '18 at 0:40
Exactly what I was looking for, thank you very much!!
– Theo
Nov 25 '18 at 6:58
1
1
If you are going to use code based on another answer, it might be good to mention that.
– Bryan Oakley
Nov 25 '18 at 0:40
If you are going to use code based on another answer, it might be good to mention that.
– Bryan Oakley
Nov 25 '18 at 0:40
Exactly what I was looking for, thank you very much!!
– Theo
Nov 25 '18 at 6:58
Exactly what I was looking for, thank you very much!!
– Theo
Nov 25 '18 at 6:58
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53462979%2fpython-tkinter-how-to-put-widgets-from-one-class-onto-a-window-in-another-clas%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
What is the line you are using to import Tkinter? Not on windows, but
import Tkinter
and inheriting fromTkinter.Tk
is what works on linux.– jackw11111
Nov 24 '18 at 23:07
@jackw11111 I've added the import lines to my code. Also I am using windows.
– Theo
Nov 24 '18 at 23:16
When you use
import tkinter as tk
as the only import statement, see if inheriting fromtk.Tk
works.– jackw11111
Nov 24 '18 at 23:21
So
class TopPanel(Tk.tk)
becomesclass TopPanel(tk.Tk)
and the same change forMainGuiApp
.– jackw11111
Nov 24 '18 at 23:25
@jackw11111 this works! but it creates a new window for TopPanel. How can I have the contents of TopPanel on MainGuiApp
– Theo
Nov 24 '18 at 23:26