Introduction:

I believe a lot of people have such a worry, I go home from work every day will think very long today to do what to eat what, chili fried meat, only yesterday to eat, hot and sour potato slices only before the day! In short, EVERY day I think about what to eat at home today, how to cook! If you ask me why I don’t order takeaways, first of all, takeaways may not be very clean, so I can’t trust myself to eat them. Second, many takeaways are terrible. Especially the noodles I eat every morning, the noodle shop can still open. It’s awful, so let’s make a menu of whatever it gives me today. So every day don’t have to think about it, if you use it, you can share it directly with ha, source code at the end of the article!

Get a recipe generator to randomly generate “three dishes and one soup”, perfect solution to the problem of buying food

Project introduction

From the “kitchen” climb “home cooking” quickly dish next meal 】 【 】 【 soup 】 recently popular in four types of dishes, stored in a CSV file, create a interface, randomly generated three vegetables a soup recipe, the menu includes the name, ingredients, grading, tutorial links, and shows the ingredients in the interface word cloud, the user can repeat, can generate many times the menu:

www.xiachufang.com/

The results show

Run ui_support.py:

If you are not satisfied, you can also click the “Clear” button to continue to rebuild oh ~

knowledge

From this project, you can learn the following:

1. Basic process of crawler

2. Xpath extracts data

3. Create, write, and read CSV files

4. Pandas randomly select the data sample()

5. DateFrame into the List

6. Use of UI generation tool Page

7. Add event triggering logic based on generated UI code

8. Word cloud making

Project process

There is a read. TXT file in the project file, which also describes the module division of the project.

Spider. py is a crawler file that crawls the data we need. The logic is: CSV creation, url creation, traversal access, data extraction, and CSV writing.

There is a problem with the OBTAINED CSV, it will be garbled when opened, set to UTF8, and GBK cannot be displayed in WPS normally, but it is displayed normally when opened with TXT. After testing, it is also displayed normally in UI interface, because there are some emoticon characters in the food ingredients, and the obtained CSV does not need any processing:

Next to make the UI interface, using the page tool to generate interface code, about this tool installation configuration reference:

Python Script GUI Interface Generation Tool

Xiaobian here is designed, and then a brief introduction:

From the left “Widget Toolbar” control bar, select the corresponding control to the middle window. For the button control, we need to add the trigger command that will run the logic by clicking “Build menu”.

Select the “Menu Generation” control, and then select “Attribute” in the “Attribute Editor” column. Write the triggering function name in “Command”, and “text” and “Tooltip” are displayed as text respectively.

After the design, save the first, small editor save file named UI, it is saved as UI. TCL file, now put the interface code also save:

Click “Save” to Save both files, which will be saved in the same directory as UI.tcl.

“Python GUI” is the interface logic. The saved file is called ui.py and does not need to be touched.

The “Support Module” is the trigger event code, and our logic is to add:

Open ui_support.py and find the set “command”, which is the function name:

The clean function is to clear the text box after clicking the “Clear” button:

The creat_menu function is the logic after clicking the “Generate menu” button. It randomly extracts three dishes and one soup from CSV and displays them in the text box, and displays the word cloud in the label bar.

It mainly includes: reading CSV, converting DataFrame into list, merging [Three dishes and one soup], making menu text, saving food ingredient words, inserting menu text box, generating word cloud, inserting word cloud:

Now that all the logic is done, run ui_support.py to start generating the recipe

** source code to obtain **

The full source code for this article is available here