current position:Home>Don't know what to eat every day? Python to tell you! Generate recipes and don't worry about what to eat every day!

Don't know what to eat every day? Python to tell you! Generate recipes and don't worry about what to eat every day!

2022-01-30 06:34:58 Programming small code farmer

Introduction

      I believe many people have such a worry , Every day when I come home from work, I think for a long time about what to do and eat today , Stir fried meat with chili , Only yesterday , Hot and sour shredded potatoes were made a few days ago ! In short, every day I think about what to eat at home today , How do you do it? ! If you ask me why I don't order takeout , First, the takeout may not be very clean , Don't worry about eating , Second, a lot of takeout food is too bad , Especially the powder I eat every morning , That powder shop can be opened , I might as well grab some bone soup and eat noodles in the morning ! It's terrible , So I'll have one today. What menu did it give me , Let's just do something ! So you don't have to think about it every day , If you can use , I can share it with you directly , The source code is at the end of the article !

I have enough to eat , Make a recipe generator , Random generation “ Three dishes and one soup ”, Perfect solution to the difficulty of buying vegetables ~

Project brief introduction

from “ Under the kitchen ” Crawling 【 Home Dishes 】【 Kwai Chi 】【 Serve a meal 】【 Soup soup 】 The most popular of the four dishes , Save in csv file , Make an interface , Randomly generate recipes of three dishes and one soup , The recipe contains the name of the dish , The ingredients , score , Tutorial links , And display the food words cloud in the interface , User repeatable , Recipe can be generated many times :

www.xiachufang.com/

 picture

Result display

function ui_support.py file :

 picture

 picture

If not satisfied , You can also click 【 eliminate 】 Button , Continue to regenerate ~

Knowledge point

From this project , You can learn the following :

1. Basic process of reptile

2.xpath Extract the data

3. establish , write in , Read csv

4.pandas Randomly selected data sample()

5.DateFrame To List

6.ui Generation tool page Use

7. Based on build ui Code , Add event trigger logic

8. Ci cloud production

Project process

There is one in the project file read.txt file , It also describes the module division of the project .

spider.py For crawler files , Crawling the data we need , The logic is : establish csv, establish url Post traversal access , Extract the data , write in csv.

In the csv There is a question , Open it and it will be a mess , Set to utf8,gbk Can't work normally wps Show , But with txt Open is normal display , After testing , stay ui The interface display is normal , This is because there are some emoticons in the ingredients , Acquired csv No processing required :

 picture

Next up ui Interface , Used page Tools to generate interface code , Refer to for the installation and configuration of this tool :

《Python Script GUI Interface generation tool 》

Xiaobian, it's designed here , Just a little bit more :

 picture

From left side “Widget Toolbar” Control bar , Select the corresponding control to the middle window , For button controls , We need to add trigger command , Click on “ generate menu ” It will run the corresponding logic .

Choose “ Menu generation ” Control , Choose again “Attribute Editor” Hurdles “Attribute” , stay “command” Write trigger function name ,“text” "tooltip" Display for text , Prompt label :

 picture

After design , First save , The name of the saved file is ui, It is saved as ui.tcl file , Now save the interface code :

 picture

Click the respectively “Save” Save these two files , Will be saved in and ui.tcl Same directory for .

“python GUI” It's interface logic , The saved file name is ui.py, No need to move .

“Support Module” Is the trigger event code , Our corresponding logic is to add :

 picture

open ui_support.py , Found set “command”, Function name :

 picture

clean Function is click 【 eliminate 】 After button , Clear text box :

 picture

creat_menu Function is click 【 Generate recipes 】 Logic after button , from csv Randomly selected three dishes and one soup in the text box , Show word cloud in tab bar .

It is mainly : Read csv,DataFrame Turn into list, Merge 【 Three dishes and one soup 】, Make menu text , Preservation of food words , Menu text box insert , Word cloud generation , Parenthesis cloud :

 picture

 picture

 picture

So all the logic is done , function ui_support.py You can start the recipe generation ~

**
The source code for **

You need the complete source code of this article. Click here to get

copyright notice
author[Programming small code farmer],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/01/202201300634571381.html

Random recommended