When trying to list pickled data I only get data that was last stored, how do I display all pickled data?How to generate all permutations of a list in PythonHow can I get a list of locally installed Python modules?Getting the last element of a listGetting a list of all subdirectories in the current directoryHow do I get the number of elements in a list?How do I list all files of a directory?How can I get the concatenation of two lists in Python without modifying either one?Get the data received in a Flask requestHow to get all pickled dataCreating a variable from one class to another
Fake TL072/TL074 IC's - how does the economics of it work?
Is it sportsmanlike to waste opponents' time by giving check at the end of the game?
Is it a good idea to contact a candidate?
What is the meaning of Text inside of AMS logo
What type of beer is best for beer battered fish?
Canonical reference for Chern characteristic classes
What are these criss-cross patterns close to Cambridge Airport (UK)?
Which fallacy: "If white privilege exists, why did Elizabeth Warren pretend to be an Indian?"
Translation Golf XLIX - An Accurate Shot
How to interpret Residuals vs. Fitted Plot
Why did the Bohr Model Successfully calculate some of the energy levels in hydrogen?
Why use [FormalN]?
Spacing between ArcMap class name and description in the legend
Giving a talk on a different topic than what we discussed
I have stack-exchanged through my undergrad math program. Am I likely to succeed in Mathematics PhD programs?
What information could a Time Traveller give to the Germans to make them win the war?
Why is potassium ferrocyanide considered safe for consumption, when it is just one reaction away from the highly toxic potassium cyanide?
What is a Thanos Word™?
How to avoid answering "what were you sick with"?
Is there a way to realize a function of type ((a -> b) -> b) -> Either a b?
When should we use "Got it?" and "Get it?"
Need Good OOP Design For World and Countries Problem
Was there a clearly identifiable "first computer" to use or demonstrate the use of virtual memory?
Why does Smaug have 4 legs in the 1st movie but only 2 legs in the 2nd?
When trying to list pickled data I only get data that was last stored, how do I display all pickled data?
How to generate all permutations of a list in PythonHow can I get a list of locally installed Python modules?Getting the last element of a listGetting a list of all subdirectories in the current directoryHow do I get the number of elements in a list?How do I list all files of a directory?How can I get the concatenation of two lists in Python without modifying either one?Get the data received in a Flask requestHow to get all pickled dataCreating a variable from one class to another
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
I want to display all my pickled values in a list. However, when I run the program and press the button that takes me to the page where all the values will be displayed, I'm only shown a single value. This value is from the last time the program was run. When I close the program and try again it displays the value from my last attempt.
here's what I'm talking about: https://imgur.com/a/m79BkMY
This is the code where the pickling and display of data happens
class Streak():
def __init__(self, action, streak_num, day, hour, minute, stored_streaks):
self.action = action
self.streak_num = streak_num
self.day = day
self.hour = hour
self.minute = minute
def get_time(self):
self.action = app.frames[PageOne].action_text.get()
self.streak_num = int(app.frames[PageOne].streak_num_text.get())
self.day = int(app.frames[PageOne].due_day.get())
self.hour = int(app.frames[PageOne].due_hour.get())
self.minute = int(app.frames[PageOne].due_minute.get())
stored_streaks =
total = (self.day * 86400) + (self.hour * 3600) + (self.minute * 60)
streak_input = "action": self.action , "streak_num": self.streak_num,
"total": total
store_streak = stored_streaks.update(streak_input.copy())
with open("streak.pkl", "wb") as wpickle_file:
pickle.dump(stored_streaks, wpickle_file)
print(streak_input)
app.show_frame(PageTwo)
def read_file(self):
with open("streak.pkl", "rb") as pickle_file:
stored_streaks = pickle.load(pickle_file)
#stored_streaks.update(streak_input) ## comeback to this
return stored_streaks
class PageOne(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
streak_title = tk.Label(self, text="New Streak", font=XLARGE_FONT)
streak_title.pack()
action_label = tk.Label(self, text="Action", font=LARGE_FONT)
action_label.pack(anchor="w", padx=30, pady=10)
self.action_text = tk.Entry(self, width=250)
self.action_text.pack(anchor="w", padx=30)
streak_num_label = tk.Label(self, text="Streak #", font=LARGE_FONT)
streak_num_label.pack(anchor="w", padx=30, pady=10)
self.streak_num_text = tk.Entry(self, width=250)
self.streak_num_text.pack(anchor="w", padx=30, pady=10)
day_label = tk.Label(self, text="Day(s)")
day_label.pack()
self.due_day = tk.Entry(self)
self.due_day.pack()
hour_label = tk.Label(self, text="Hour(s)")
hour_label.pack()
self.due_hour = tk.Entry(self)
self.due_hour.pack()
minute_label = tk.Label(self, text="Minute(s)")
minute_label.pack()
self.due_minute = tk.Entry(self)
self.due_minute.pack()
get_time_btn = tk.Button(self, bg="medium purple", text="Add",
command=lambda: Streak.get_time(self))
get_time_btn.pack()
class PageTwo(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
test_label = tk.Label(self, text="TEST", font=XLARGE_FONT)
test_label.pack()
streak_list = Streak.read_file(self)
action_list = streak_list.get("action", "none")
display_list = [action_list]
for action_list in display_list:
list = tk.Button(self, bg="medium purple", text=action_list)
list.pack()
back_btn = tk.Button(self, bg="medium purple", text="BACK",
command=lambda: controller.show_frame(PageOne))
back_btn.pack()
I included print so I could make sure that the get_time function was working. From the first image this was printed:
'action': 'first', 'streak_num': 1, 'total': 120
When I print streak_list it prints the data that was input before the program closed
python tkinter pickle
|
show 4 more comments
I want to display all my pickled values in a list. However, when I run the program and press the button that takes me to the page where all the values will be displayed, I'm only shown a single value. This value is from the last time the program was run. When I close the program and try again it displays the value from my last attempt.
here's what I'm talking about: https://imgur.com/a/m79BkMY
This is the code where the pickling and display of data happens
class Streak():
def __init__(self, action, streak_num, day, hour, minute, stored_streaks):
self.action = action
self.streak_num = streak_num
self.day = day
self.hour = hour
self.minute = minute
def get_time(self):
self.action = app.frames[PageOne].action_text.get()
self.streak_num = int(app.frames[PageOne].streak_num_text.get())
self.day = int(app.frames[PageOne].due_day.get())
self.hour = int(app.frames[PageOne].due_hour.get())
self.minute = int(app.frames[PageOne].due_minute.get())
stored_streaks =
total = (self.day * 86400) + (self.hour * 3600) + (self.minute * 60)
streak_input = "action": self.action , "streak_num": self.streak_num,
"total": total
store_streak = stored_streaks.update(streak_input.copy())
with open("streak.pkl", "wb") as wpickle_file:
pickle.dump(stored_streaks, wpickle_file)
print(streak_input)
app.show_frame(PageTwo)
def read_file(self):
with open("streak.pkl", "rb") as pickle_file:
stored_streaks = pickle.load(pickle_file)
#stored_streaks.update(streak_input) ## comeback to this
return stored_streaks
class PageOne(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
streak_title = tk.Label(self, text="New Streak", font=XLARGE_FONT)
streak_title.pack()
action_label = tk.Label(self, text="Action", font=LARGE_FONT)
action_label.pack(anchor="w", padx=30, pady=10)
self.action_text = tk.Entry(self, width=250)
self.action_text.pack(anchor="w", padx=30)
streak_num_label = tk.Label(self, text="Streak #", font=LARGE_FONT)
streak_num_label.pack(anchor="w", padx=30, pady=10)
self.streak_num_text = tk.Entry(self, width=250)
self.streak_num_text.pack(anchor="w", padx=30, pady=10)
day_label = tk.Label(self, text="Day(s)")
day_label.pack()
self.due_day = tk.Entry(self)
self.due_day.pack()
hour_label = tk.Label(self, text="Hour(s)")
hour_label.pack()
self.due_hour = tk.Entry(self)
self.due_hour.pack()
minute_label = tk.Label(self, text="Minute(s)")
minute_label.pack()
self.due_minute = tk.Entry(self)
self.due_minute.pack()
get_time_btn = tk.Button(self, bg="medium purple", text="Add",
command=lambda: Streak.get_time(self))
get_time_btn.pack()
class PageTwo(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
test_label = tk.Label(self, text="TEST", font=XLARGE_FONT)
test_label.pack()
streak_list = Streak.read_file(self)
action_list = streak_list.get("action", "none")
display_list = [action_list]
for action_list in display_list:
list = tk.Button(self, bg="medium purple", text=action_list)
list.pack()
back_btn = tk.Button(self, bg="medium purple", text="BACK",
command=lambda: controller.show_frame(PageOne))
back_btn.pack()
I included print so I could make sure that the get_time function was working. From the first image this was printed:
'action': 'first', 'streak_num': 1, 'total': 120
When I print streak_list it prints the data that was input before the program closed
python tkinter pickle
Didn't you reset your stored_streaks every time when you call the get_time method?
– Henry Yik
Mar 29 at 1:30
Oh, is it because I have an empty dictionary?
– EastCoastYam
Mar 29 at 1:34
Yes. Move the dictionary to init and make it an attribute instead.
– Henry Yik
Mar 29 at 2:50
I moved it to init of the Streak class and I still get the same problem
– EastCoastYam
Mar 29 at 5:07
how do you create the instance of classStreak
? Looks like its taking a couple arguments but yourget_time
method completely overwrites them.
– Henry Yik
Mar 29 at 5:33
|
show 4 more comments
I want to display all my pickled values in a list. However, when I run the program and press the button that takes me to the page where all the values will be displayed, I'm only shown a single value. This value is from the last time the program was run. When I close the program and try again it displays the value from my last attempt.
here's what I'm talking about: https://imgur.com/a/m79BkMY
This is the code where the pickling and display of data happens
class Streak():
def __init__(self, action, streak_num, day, hour, minute, stored_streaks):
self.action = action
self.streak_num = streak_num
self.day = day
self.hour = hour
self.minute = minute
def get_time(self):
self.action = app.frames[PageOne].action_text.get()
self.streak_num = int(app.frames[PageOne].streak_num_text.get())
self.day = int(app.frames[PageOne].due_day.get())
self.hour = int(app.frames[PageOne].due_hour.get())
self.minute = int(app.frames[PageOne].due_minute.get())
stored_streaks =
total = (self.day * 86400) + (self.hour * 3600) + (self.minute * 60)
streak_input = "action": self.action , "streak_num": self.streak_num,
"total": total
store_streak = stored_streaks.update(streak_input.copy())
with open("streak.pkl", "wb") as wpickle_file:
pickle.dump(stored_streaks, wpickle_file)
print(streak_input)
app.show_frame(PageTwo)
def read_file(self):
with open("streak.pkl", "rb") as pickle_file:
stored_streaks = pickle.load(pickle_file)
#stored_streaks.update(streak_input) ## comeback to this
return stored_streaks
class PageOne(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
streak_title = tk.Label(self, text="New Streak", font=XLARGE_FONT)
streak_title.pack()
action_label = tk.Label(self, text="Action", font=LARGE_FONT)
action_label.pack(anchor="w", padx=30, pady=10)
self.action_text = tk.Entry(self, width=250)
self.action_text.pack(anchor="w", padx=30)
streak_num_label = tk.Label(self, text="Streak #", font=LARGE_FONT)
streak_num_label.pack(anchor="w", padx=30, pady=10)
self.streak_num_text = tk.Entry(self, width=250)
self.streak_num_text.pack(anchor="w", padx=30, pady=10)
day_label = tk.Label(self, text="Day(s)")
day_label.pack()
self.due_day = tk.Entry(self)
self.due_day.pack()
hour_label = tk.Label(self, text="Hour(s)")
hour_label.pack()
self.due_hour = tk.Entry(self)
self.due_hour.pack()
minute_label = tk.Label(self, text="Minute(s)")
minute_label.pack()
self.due_minute = tk.Entry(self)
self.due_minute.pack()
get_time_btn = tk.Button(self, bg="medium purple", text="Add",
command=lambda: Streak.get_time(self))
get_time_btn.pack()
class PageTwo(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
test_label = tk.Label(self, text="TEST", font=XLARGE_FONT)
test_label.pack()
streak_list = Streak.read_file(self)
action_list = streak_list.get("action", "none")
display_list = [action_list]
for action_list in display_list:
list = tk.Button(self, bg="medium purple", text=action_list)
list.pack()
back_btn = tk.Button(self, bg="medium purple", text="BACK",
command=lambda: controller.show_frame(PageOne))
back_btn.pack()
I included print so I could make sure that the get_time function was working. From the first image this was printed:
'action': 'first', 'streak_num': 1, 'total': 120
When I print streak_list it prints the data that was input before the program closed
python tkinter pickle
I want to display all my pickled values in a list. However, when I run the program and press the button that takes me to the page where all the values will be displayed, I'm only shown a single value. This value is from the last time the program was run. When I close the program and try again it displays the value from my last attempt.
here's what I'm talking about: https://imgur.com/a/m79BkMY
This is the code where the pickling and display of data happens
class Streak():
def __init__(self, action, streak_num, day, hour, minute, stored_streaks):
self.action = action
self.streak_num = streak_num
self.day = day
self.hour = hour
self.minute = minute
def get_time(self):
self.action = app.frames[PageOne].action_text.get()
self.streak_num = int(app.frames[PageOne].streak_num_text.get())
self.day = int(app.frames[PageOne].due_day.get())
self.hour = int(app.frames[PageOne].due_hour.get())
self.minute = int(app.frames[PageOne].due_minute.get())
stored_streaks =
total = (self.day * 86400) + (self.hour * 3600) + (self.minute * 60)
streak_input = "action": self.action , "streak_num": self.streak_num,
"total": total
store_streak = stored_streaks.update(streak_input.copy())
with open("streak.pkl", "wb") as wpickle_file:
pickle.dump(stored_streaks, wpickle_file)
print(streak_input)
app.show_frame(PageTwo)
def read_file(self):
with open("streak.pkl", "rb") as pickle_file:
stored_streaks = pickle.load(pickle_file)
#stored_streaks.update(streak_input) ## comeback to this
return stored_streaks
class PageOne(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
streak_title = tk.Label(self, text="New Streak", font=XLARGE_FONT)
streak_title.pack()
action_label = tk.Label(self, text="Action", font=LARGE_FONT)
action_label.pack(anchor="w", padx=30, pady=10)
self.action_text = tk.Entry(self, width=250)
self.action_text.pack(anchor="w", padx=30)
streak_num_label = tk.Label(self, text="Streak #", font=LARGE_FONT)
streak_num_label.pack(anchor="w", padx=30, pady=10)
self.streak_num_text = tk.Entry(self, width=250)
self.streak_num_text.pack(anchor="w", padx=30, pady=10)
day_label = tk.Label(self, text="Day(s)")
day_label.pack()
self.due_day = tk.Entry(self)
self.due_day.pack()
hour_label = tk.Label(self, text="Hour(s)")
hour_label.pack()
self.due_hour = tk.Entry(self)
self.due_hour.pack()
minute_label = tk.Label(self, text="Minute(s)")
minute_label.pack()
self.due_minute = tk.Entry(self)
self.due_minute.pack()
get_time_btn = tk.Button(self, bg="medium purple", text="Add",
command=lambda: Streak.get_time(self))
get_time_btn.pack()
class PageTwo(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
test_label = tk.Label(self, text="TEST", font=XLARGE_FONT)
test_label.pack()
streak_list = Streak.read_file(self)
action_list = streak_list.get("action", "none")
display_list = [action_list]
for action_list in display_list:
list = tk.Button(self, bg="medium purple", text=action_list)
list.pack()
back_btn = tk.Button(self, bg="medium purple", text="BACK",
command=lambda: controller.show_frame(PageOne))
back_btn.pack()
I included print so I could make sure that the get_time function was working. From the first image this was printed:
'action': 'first', 'streak_num': 1, 'total': 120
When I print streak_list it prints the data that was input before the program closed
python tkinter pickle
python tkinter pickle
edited Mar 29 at 16:52
EastCoastYam
asked Mar 28 at 21:52
EastCoastYamEastCoastYam
13 bronze badges
13 bronze badges
Didn't you reset your stored_streaks every time when you call the get_time method?
– Henry Yik
Mar 29 at 1:30
Oh, is it because I have an empty dictionary?
– EastCoastYam
Mar 29 at 1:34
Yes. Move the dictionary to init and make it an attribute instead.
– Henry Yik
Mar 29 at 2:50
I moved it to init of the Streak class and I still get the same problem
– EastCoastYam
Mar 29 at 5:07
how do you create the instance of classStreak
? Looks like its taking a couple arguments but yourget_time
method completely overwrites them.
– Henry Yik
Mar 29 at 5:33
|
show 4 more comments
Didn't you reset your stored_streaks every time when you call the get_time method?
– Henry Yik
Mar 29 at 1:30
Oh, is it because I have an empty dictionary?
– EastCoastYam
Mar 29 at 1:34
Yes. Move the dictionary to init and make it an attribute instead.
– Henry Yik
Mar 29 at 2:50
I moved it to init of the Streak class and I still get the same problem
– EastCoastYam
Mar 29 at 5:07
how do you create the instance of classStreak
? Looks like its taking a couple arguments but yourget_time
method completely overwrites them.
– Henry Yik
Mar 29 at 5:33
Didn't you reset your stored_streaks every time when you call the get_time method?
– Henry Yik
Mar 29 at 1:30
Didn't you reset your stored_streaks every time when you call the get_time method?
– Henry Yik
Mar 29 at 1:30
Oh, is it because I have an empty dictionary?
– EastCoastYam
Mar 29 at 1:34
Oh, is it because I have an empty dictionary?
– EastCoastYam
Mar 29 at 1:34
Yes. Move the dictionary to init and make it an attribute instead.
– Henry Yik
Mar 29 at 2:50
Yes. Move the dictionary to init and make it an attribute instead.
– Henry Yik
Mar 29 at 2:50
I moved it to init of the Streak class and I still get the same problem
– EastCoastYam
Mar 29 at 5:07
I moved it to init of the Streak class and I still get the same problem
– EastCoastYam
Mar 29 at 5:07
how do you create the instance of class
Streak
? Looks like its taking a couple arguments but your get_time
method completely overwrites them.– Henry Yik
Mar 29 at 5:33
how do you create the instance of class
Streak
? Looks like its taking a couple arguments but your get_time
method completely overwrites them.– Henry Yik
Mar 29 at 5:33
|
show 4 more comments
0
active
oldest
votes
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/4.0/"u003ecc by-sa 4.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%2f55407417%2fwhen-trying-to-list-pickled-data-i-only-get-data-that-was-last-stored-how-do-i%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f55407417%2fwhen-trying-to-list-pickled-data-i-only-get-data-that-was-last-stored-how-do-i%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
Didn't you reset your stored_streaks every time when you call the get_time method?
– Henry Yik
Mar 29 at 1:30
Oh, is it because I have an empty dictionary?
– EastCoastYam
Mar 29 at 1:34
Yes. Move the dictionary to init and make it an attribute instead.
– Henry Yik
Mar 29 at 2:50
I moved it to init of the Streak class and I still get the same problem
– EastCoastYam
Mar 29 at 5:07
how do you create the instance of class
Streak
? Looks like its taking a couple arguments but yourget_time
method completely overwrites them.– Henry Yik
Mar 29 at 5:33