[Tutor] Use of states to control Tkinter app navigation

Jon Davies jon_davies17 at hotmail.co.uk
Sat Apr 11 05:54:02 EDT 2020


Hi,

My apologies - didn't think about the files.

I've attached some links below to the aforementioned video/code. Hopefully they work!

https://www.dropbox.com/s/ybk3hpa989yt666/bandicam%202020-04-03%2013-03-20-920.mp4?dl=0

https://www.dropbox.com/s/ybk3hpa989yt666/bandicam%202020-04-03%2013-03-20-920.mp4?dl=0

Kind regards,

Jon

________________________________
From: Jon Davies
Sent: 10 April 2020 17:20
To: tutor at python.org <tutor at python.org>
Subject: Use of states to control Tkinter app navigation

Hi there,

I've been progressing with the creation of my Petrol station Pay-at-pump app using Tkinter, which is aiming to provide language translation/currency conversion. I have been steered towards the use of states to help provide clearer navigation of my app, as well as provide the function to completely reset the app at various stages to a fresh instance (i.e. to reverse any changes to widgets, variables etc.).

The concept of states seems simple and easy to understand, although again with my limited knowledge of implementation it has proven to be a bit of a challenge. I've made a duplicate of my previous working version of the file to test the functionality (see attached). I can provide the working code/file as well if needed.

I've tried to implement the use of states to control the movement of frames through the buttons (i.e. instead of show_frame function that I have used previously). I've also tried to create individual restart methods for each frame using the state model. I think my syntax is now correct, but when I try to run it gives me  "NameError: name 'SelectLanguagePage' is not defined" at line 36 (i.e. where I outline the state dictionary).

I can only imagine this is because the states section is perhaps not in the right place? Or does each state/class need to be outlined within the init of each class?

I've attached a video of the problems I was facing with my working file, i.e. the use of the show_frame function to navigate frames - it was not functioning properly and showing pages in strange orders depending on buttons clicked.

Essentially, I want to the app to have simple navigation from start to finish through the use of the buttons (and states), i.e. select language > select payment type > select currency > start fuelling > finish page.

Kind regards,

Jon



More information about the Tutor mailing list