Tkinter Notebook widgetNotebook widget in TkinterInstall tkinter for Pythonttk tkinter multiple frames/windowsadding an on_release action to a kivy buttonHow to make IPython notebook matplotlib plot inlineDerived panel classes in wxpythonwxpython - Erase background erases non-background componentsCenter widgets in KivyKivy widgets behaving erraticallyTkInter Frame doesn't load if another function is called
No shading in ContourPlot3D
I found a password with hashcat but it doesn't work
How can I restore a master database from its bak file?
Setting up the trap
How can the US president give an order to a civilian?
Time at 1 g acceleration to travel 100 000 light years
Counterfeit checks were created for my account. How does this type of fraud work?
What kind of chart is this?
What is the highest power supply a Raspberry pi 3 B can handle without getting damaged?
Leaving job close to major deadlines
Predict the product from the reaction
Why one uses 了 and the other one doesn’t?
Draw a symmetric alien head
If the mass of the Earth is decreasing by sending debris in space, does its angular momentum also decrease?
How to modify a string without altering its text properties
How can a clan of females defend themselves in the ancient world against wandering bands?
Why there is a red color in right side?
"Prove that ∂A is closed given ∂A = Cl(A) − Int(A)"
How much steel armor can you wear and still be able to swim?
Teferi's Time Twist and Gideon's Sacrifice
How did Frodo know where the Bree village was?
What is the maximum that Player 1 can win?
Why is it 出差去 and not 去出差?
Definition of 'vrit'
Tkinter Notebook widget
Notebook widget in TkinterInstall tkinter for Pythonttk tkinter multiple frames/windowsadding an on_release action to a kivy buttonHow to make IPython notebook matplotlib plot inlineDerived panel classes in wxpythonwxpython - Erase background erases non-background componentsCenter widgets in KivyKivy widgets behaving erraticallyTkInter Frame doesn't load if another function is called
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am trying to create multiple tabs using ttk.Notebook
widget. I am creating a simple multi-tab notepad. but I don't know how to deal with the NoteBook widget. but when I click on save button it overrides all tabs text area that because of I declared there self.tx.get("1.0","end-1c")
.all written file change their text according to last text. Thanks for helping me
#-*- coding: utf-8 -*-
import tkinter.ttk as ttks
from tkinter import LEFT,RIGHT,X,Y,BOTH
class MainUI:
def __init__(self,master):
self.master = master
self.nb = ttks.Notebook(self.master)
self.nb.pack(fill='both',expand=1)
self.name = ttks.Entry(self.master)
self.name.pack()
self.save_tab = ttks.Button(self.master,text="save",command=lambda:self.save_file()).pack()
#tab1
self.page1 = ttks.Frame(self.nb)
self.txt = ttks.tkinter.Text(self.page1)
self.txt.pack(fill='both',expand=1)
self.nb.add(self.page1,text="tab1")
self.page2 = ttks.Frame(self.nb)
self.nb.add(self.page2,text="tab2")
self.master.bind('',self.add_tabs)
def add_tabs(self,event):
self.page_name = ttks.Frame(self.nb)
self.tx = ttks.tkinter.Text(self.page_name)
self.tx.pack(fill=BOTH,expand=1)
self.nb.add(self.page_name,text="pagename")
def save_file(self):
self.fname = self.name.get()
self.txtinput = self.tx.get("1.0","end-1c")
with open(self.fname,'w') as f:
f.write(self.txtinput)
if __name__ == "__main__":
root = ttks.tkinter.Tk()
root.title('Tabs>>')
root.geometry('500x500')
MainUI(root)
root.mainloop()
after Implementing below code got following Exception
python tkinter ttk
add a comment |
I am trying to create multiple tabs using ttk.Notebook
widget. I am creating a simple multi-tab notepad. but I don't know how to deal with the NoteBook widget. but when I click on save button it overrides all tabs text area that because of I declared there self.tx.get("1.0","end-1c")
.all written file change their text according to last text. Thanks for helping me
#-*- coding: utf-8 -*-
import tkinter.ttk as ttks
from tkinter import LEFT,RIGHT,X,Y,BOTH
class MainUI:
def __init__(self,master):
self.master = master
self.nb = ttks.Notebook(self.master)
self.nb.pack(fill='both',expand=1)
self.name = ttks.Entry(self.master)
self.name.pack()
self.save_tab = ttks.Button(self.master,text="save",command=lambda:self.save_file()).pack()
#tab1
self.page1 = ttks.Frame(self.nb)
self.txt = ttks.tkinter.Text(self.page1)
self.txt.pack(fill='both',expand=1)
self.nb.add(self.page1,text="tab1")
self.page2 = ttks.Frame(self.nb)
self.nb.add(self.page2,text="tab2")
self.master.bind('',self.add_tabs)
def add_tabs(self,event):
self.page_name = ttks.Frame(self.nb)
self.tx = ttks.tkinter.Text(self.page_name)
self.tx.pack(fill=BOTH,expand=1)
self.nb.add(self.page_name,text="pagename")
def save_file(self):
self.fname = self.name.get()
self.txtinput = self.tx.get("1.0","end-1c")
with open(self.fname,'w') as f:
f.write(self.txtinput)
if __name__ == "__main__":
root = ttks.tkinter.Tk()
root.title('Tabs>>')
root.geometry('500x500')
MainUI(root)
root.mainloop()
after Implementing below code got following Exception
python tkinter ttk
"click on save button it overrides all tabs text area": It's not clear what you mean here. Edit your Question and explain in detail, even showing example output.
– stovfl
Mar 24 at 16:34
Did you say: Click on[Save]
with name"name1.txt"
will override the content of the existing file"name.txt"
with the content of the lastttks.tkinter.Text(...
?
– stovfl
Mar 25 at 11:08
yes its override all previous files
– Juna
Mar 25 at 17:19
Treid your code and could not reproduce your issue. Please make sure, code you posts actually behaves as you claim.
– stovfl
Mar 25 at 17:33
it is the same code
– Juna
Mar 25 at 17:43
add a comment |
I am trying to create multiple tabs using ttk.Notebook
widget. I am creating a simple multi-tab notepad. but I don't know how to deal with the NoteBook widget. but when I click on save button it overrides all tabs text area that because of I declared there self.tx.get("1.0","end-1c")
.all written file change their text according to last text. Thanks for helping me
#-*- coding: utf-8 -*-
import tkinter.ttk as ttks
from tkinter import LEFT,RIGHT,X,Y,BOTH
class MainUI:
def __init__(self,master):
self.master = master
self.nb = ttks.Notebook(self.master)
self.nb.pack(fill='both',expand=1)
self.name = ttks.Entry(self.master)
self.name.pack()
self.save_tab = ttks.Button(self.master,text="save",command=lambda:self.save_file()).pack()
#tab1
self.page1 = ttks.Frame(self.nb)
self.txt = ttks.tkinter.Text(self.page1)
self.txt.pack(fill='both',expand=1)
self.nb.add(self.page1,text="tab1")
self.page2 = ttks.Frame(self.nb)
self.nb.add(self.page2,text="tab2")
self.master.bind('',self.add_tabs)
def add_tabs(self,event):
self.page_name = ttks.Frame(self.nb)
self.tx = ttks.tkinter.Text(self.page_name)
self.tx.pack(fill=BOTH,expand=1)
self.nb.add(self.page_name,text="pagename")
def save_file(self):
self.fname = self.name.get()
self.txtinput = self.tx.get("1.0","end-1c")
with open(self.fname,'w') as f:
f.write(self.txtinput)
if __name__ == "__main__":
root = ttks.tkinter.Tk()
root.title('Tabs>>')
root.geometry('500x500')
MainUI(root)
root.mainloop()
after Implementing below code got following Exception
python tkinter ttk
I am trying to create multiple tabs using ttk.Notebook
widget. I am creating a simple multi-tab notepad. but I don't know how to deal with the NoteBook widget. but when I click on save button it overrides all tabs text area that because of I declared there self.tx.get("1.0","end-1c")
.all written file change their text according to last text. Thanks for helping me
#-*- coding: utf-8 -*-
import tkinter.ttk as ttks
from tkinter import LEFT,RIGHT,X,Y,BOTH
class MainUI:
def __init__(self,master):
self.master = master
self.nb = ttks.Notebook(self.master)
self.nb.pack(fill='both',expand=1)
self.name = ttks.Entry(self.master)
self.name.pack()
self.save_tab = ttks.Button(self.master,text="save",command=lambda:self.save_file()).pack()
#tab1
self.page1 = ttks.Frame(self.nb)
self.txt = ttks.tkinter.Text(self.page1)
self.txt.pack(fill='both',expand=1)
self.nb.add(self.page1,text="tab1")
self.page2 = ttks.Frame(self.nb)
self.nb.add(self.page2,text="tab2")
self.master.bind('',self.add_tabs)
def add_tabs(self,event):
self.page_name = ttks.Frame(self.nb)
self.tx = ttks.tkinter.Text(self.page_name)
self.tx.pack(fill=BOTH,expand=1)
self.nb.add(self.page_name,text="pagename")
def save_file(self):
self.fname = self.name.get()
self.txtinput = self.tx.get("1.0","end-1c")
with open(self.fname,'w') as f:
f.write(self.txtinput)
if __name__ == "__main__":
root = ttks.tkinter.Tk()
root.title('Tabs>>')
root.geometry('500x500')
MainUI(root)
root.mainloop()
after Implementing below code got following Exception
python tkinter ttk
python tkinter ttk
edited Mar 25 at 15:41
Juna
asked Mar 24 at 14:29
JunaJuna
207
207
"click on save button it overrides all tabs text area": It's not clear what you mean here. Edit your Question and explain in detail, even showing example output.
– stovfl
Mar 24 at 16:34
Did you say: Click on[Save]
with name"name1.txt"
will override the content of the existing file"name.txt"
with the content of the lastttks.tkinter.Text(...
?
– stovfl
Mar 25 at 11:08
yes its override all previous files
– Juna
Mar 25 at 17:19
Treid your code and could not reproduce your issue. Please make sure, code you posts actually behaves as you claim.
– stovfl
Mar 25 at 17:33
it is the same code
– Juna
Mar 25 at 17:43
add a comment |
"click on save button it overrides all tabs text area": It's not clear what you mean here. Edit your Question and explain in detail, even showing example output.
– stovfl
Mar 24 at 16:34
Did you say: Click on[Save]
with name"name1.txt"
will override the content of the existing file"name.txt"
with the content of the lastttks.tkinter.Text(...
?
– stovfl
Mar 25 at 11:08
yes its override all previous files
– Juna
Mar 25 at 17:19
Treid your code and could not reproduce your issue. Please make sure, code you posts actually behaves as you claim.
– stovfl
Mar 25 at 17:33
it is the same code
– Juna
Mar 25 at 17:43
"click on save button it overrides all tabs text area": It's not clear what you mean here. Edit your Question and explain in detail, even showing example output.
– stovfl
Mar 24 at 16:34
"click on save button it overrides all tabs text area": It's not clear what you mean here. Edit your Question and explain in detail, even showing example output.
– stovfl
Mar 24 at 16:34
Did you say: Click on
[Save]
with name "name1.txt"
will override the content of the existing file "name.txt"
with the content of the last ttks.tkinter.Text(...
?– stovfl
Mar 25 at 11:08
Did you say: Click on
[Save]
with name "name1.txt"
will override the content of the existing file "name.txt"
with the content of the last ttks.tkinter.Text(...
?– stovfl
Mar 25 at 11:08
yes its override all previous files
– Juna
Mar 25 at 17:19
yes its override all previous files
– Juna
Mar 25 at 17:19
Treid your code and could not reproduce your issue. Please make sure, code you posts actually behaves as you claim.
– stovfl
Mar 25 at 17:33
Treid your code and could not reproduce your issue. Please make sure, code you posts actually behaves as you claim.
– stovfl
Mar 25 at 17:33
it is the same code
– Juna
Mar 25 at 17:43
it is the same code
– Juna
Mar 25 at 17:43
add a comment |
1 Answer
1
active
oldest
votes
In add_tabs
, you are replacing the value of self.tx
each time that a new tab is added. I.e. you only remember the last created text widget. You need to:
- store all the text widgets you create (i.e. using a list)
- have some means to find the text widget in foreground, e.g. by looking at the active tab or the focused widget.
In __init__
, add:
self.txs = [] # "s" suffix to discern list and elements
in add_tabs
, use:
tx = ttks.tkinter.Text(self.page_name)
self.txs.append(tx) # append to list
tx.pack(...)
in save_file
, use:
tab_index = self.nb.index(self.nb.select())
tx = self.txs[tab_index + 1] # may need to adjust depending on how much "static" tabs are in front
txtinput = self.tx.get("1.0", "end-1c")
# ...
i got it what you wanna say but please will you explain with example should i make Notebook widget to list or frame list?
– Juna
Mar 25 at 9:52
added example code.
– Torben Klein
Mar 25 at 10:49
I implemented your example into my code but got an exception... It is too long so I update in question
– Juna
Mar 25 at 15:37
Forgot the parens afterself.nb.select
, sorry. The exception clearly indicates the erroneous line. Generally if using functions that are new to you, it is a good idea to have a look at the docs.docs.python.org/3/library/tkinter.ttk.html#notebook
– Torben Klein
Mar 26 at 6:06
Thank I fixed my problem I created list of tabs and text widgets but now fall into another problem.
– Juna
Mar 26 at 16:40
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%2f55324827%2ftkinter-notebook-widget%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 add_tabs
, you are replacing the value of self.tx
each time that a new tab is added. I.e. you only remember the last created text widget. You need to:
- store all the text widgets you create (i.e. using a list)
- have some means to find the text widget in foreground, e.g. by looking at the active tab or the focused widget.
In __init__
, add:
self.txs = [] # "s" suffix to discern list and elements
in add_tabs
, use:
tx = ttks.tkinter.Text(self.page_name)
self.txs.append(tx) # append to list
tx.pack(...)
in save_file
, use:
tab_index = self.nb.index(self.nb.select())
tx = self.txs[tab_index + 1] # may need to adjust depending on how much "static" tabs are in front
txtinput = self.tx.get("1.0", "end-1c")
# ...
i got it what you wanna say but please will you explain with example should i make Notebook widget to list or frame list?
– Juna
Mar 25 at 9:52
added example code.
– Torben Klein
Mar 25 at 10:49
I implemented your example into my code but got an exception... It is too long so I update in question
– Juna
Mar 25 at 15:37
Forgot the parens afterself.nb.select
, sorry. The exception clearly indicates the erroneous line. Generally if using functions that are new to you, it is a good idea to have a look at the docs.docs.python.org/3/library/tkinter.ttk.html#notebook
– Torben Klein
Mar 26 at 6:06
Thank I fixed my problem I created list of tabs and text widgets but now fall into another problem.
– Juna
Mar 26 at 16:40
add a comment |
In add_tabs
, you are replacing the value of self.tx
each time that a new tab is added. I.e. you only remember the last created text widget. You need to:
- store all the text widgets you create (i.e. using a list)
- have some means to find the text widget in foreground, e.g. by looking at the active tab or the focused widget.
In __init__
, add:
self.txs = [] # "s" suffix to discern list and elements
in add_tabs
, use:
tx = ttks.tkinter.Text(self.page_name)
self.txs.append(tx) # append to list
tx.pack(...)
in save_file
, use:
tab_index = self.nb.index(self.nb.select())
tx = self.txs[tab_index + 1] # may need to adjust depending on how much "static" tabs are in front
txtinput = self.tx.get("1.0", "end-1c")
# ...
i got it what you wanna say but please will you explain with example should i make Notebook widget to list or frame list?
– Juna
Mar 25 at 9:52
added example code.
– Torben Klein
Mar 25 at 10:49
I implemented your example into my code but got an exception... It is too long so I update in question
– Juna
Mar 25 at 15:37
Forgot the parens afterself.nb.select
, sorry. The exception clearly indicates the erroneous line. Generally if using functions that are new to you, it is a good idea to have a look at the docs.docs.python.org/3/library/tkinter.ttk.html#notebook
– Torben Klein
Mar 26 at 6:06
Thank I fixed my problem I created list of tabs and text widgets but now fall into another problem.
– Juna
Mar 26 at 16:40
add a comment |
In add_tabs
, you are replacing the value of self.tx
each time that a new tab is added. I.e. you only remember the last created text widget. You need to:
- store all the text widgets you create (i.e. using a list)
- have some means to find the text widget in foreground, e.g. by looking at the active tab or the focused widget.
In __init__
, add:
self.txs = [] # "s" suffix to discern list and elements
in add_tabs
, use:
tx = ttks.tkinter.Text(self.page_name)
self.txs.append(tx) # append to list
tx.pack(...)
in save_file
, use:
tab_index = self.nb.index(self.nb.select())
tx = self.txs[tab_index + 1] # may need to adjust depending on how much "static" tabs are in front
txtinput = self.tx.get("1.0", "end-1c")
# ...
In add_tabs
, you are replacing the value of self.tx
each time that a new tab is added. I.e. you only remember the last created text widget. You need to:
- store all the text widgets you create (i.e. using a list)
- have some means to find the text widget in foreground, e.g. by looking at the active tab or the focused widget.
In __init__
, add:
self.txs = [] # "s" suffix to discern list and elements
in add_tabs
, use:
tx = ttks.tkinter.Text(self.page_name)
self.txs.append(tx) # append to list
tx.pack(...)
in save_file
, use:
tab_index = self.nb.index(self.nb.select())
tx = self.txs[tab_index + 1] # may need to adjust depending on how much "static" tabs are in front
txtinput = self.tx.get("1.0", "end-1c")
# ...
edited Mar 26 at 6:02
answered Mar 25 at 6:15
Torben KleinTorben Klein
1,353815
1,353815
i got it what you wanna say but please will you explain with example should i make Notebook widget to list or frame list?
– Juna
Mar 25 at 9:52
added example code.
– Torben Klein
Mar 25 at 10:49
I implemented your example into my code but got an exception... It is too long so I update in question
– Juna
Mar 25 at 15:37
Forgot the parens afterself.nb.select
, sorry. The exception clearly indicates the erroneous line. Generally if using functions that are new to you, it is a good idea to have a look at the docs.docs.python.org/3/library/tkinter.ttk.html#notebook
– Torben Klein
Mar 26 at 6:06
Thank I fixed my problem I created list of tabs and text widgets but now fall into another problem.
– Juna
Mar 26 at 16:40
add a comment |
i got it what you wanna say but please will you explain with example should i make Notebook widget to list or frame list?
– Juna
Mar 25 at 9:52
added example code.
– Torben Klein
Mar 25 at 10:49
I implemented your example into my code but got an exception... It is too long so I update in question
– Juna
Mar 25 at 15:37
Forgot the parens afterself.nb.select
, sorry. The exception clearly indicates the erroneous line. Generally if using functions that are new to you, it is a good idea to have a look at the docs.docs.python.org/3/library/tkinter.ttk.html#notebook
– Torben Klein
Mar 26 at 6:06
Thank I fixed my problem I created list of tabs and text widgets but now fall into another problem.
– Juna
Mar 26 at 16:40
i got it what you wanna say but please will you explain with example should i make Notebook widget to list or frame list?
– Juna
Mar 25 at 9:52
i got it what you wanna say but please will you explain with example should i make Notebook widget to list or frame list?
– Juna
Mar 25 at 9:52
added example code.
– Torben Klein
Mar 25 at 10:49
added example code.
– Torben Klein
Mar 25 at 10:49
I implemented your example into my code but got an exception... It is too long so I update in question
– Juna
Mar 25 at 15:37
I implemented your example into my code but got an exception... It is too long so I update in question
– Juna
Mar 25 at 15:37
Forgot the parens after
self.nb.select
, sorry. The exception clearly indicates the erroneous line. Generally if using functions that are new to you, it is a good idea to have a look at the docs.docs.python.org/3/library/tkinter.ttk.html#notebook– Torben Klein
Mar 26 at 6:06
Forgot the parens after
self.nb.select
, sorry. The exception clearly indicates the erroneous line. Generally if using functions that are new to you, it is a good idea to have a look at the docs.docs.python.org/3/library/tkinter.ttk.html#notebook– Torben Klein
Mar 26 at 6:06
Thank I fixed my problem I created list of tabs and text widgets but now fall into another problem.
– Juna
Mar 26 at 16:40
Thank I fixed my problem I created list of tabs and text widgets but now fall into another problem.
– Juna
Mar 26 at 16:40
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%2f55324827%2ftkinter-notebook-widget%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
"click on save button it overrides all tabs text area": It's not clear what you mean here. Edit your Question and explain in detail, even showing example output.
– stovfl
Mar 24 at 16:34
Did you say: Click on
[Save]
with name"name1.txt"
will override the content of the existing file"name.txt"
with the content of the lastttks.tkinter.Text(...
?– stovfl
Mar 25 at 11:08
yes its override all previous files
– Juna
Mar 25 at 17:19
Treid your code and could not reproduce your issue. Please make sure, code you posts actually behaves as you claim.
– stovfl
Mar 25 at 17:33
it is the same code
– Juna
Mar 25 at 17:43