Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Python to develop a desktop Mini Program

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to use Python to develop a desktop Mini Program. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

Development environment:

Python 3.6

Pycharm

Code

Interface settin

1. Import module

Import tkinter as tk

two。 Instantiate a form object

Root = tk.Tk ()

3. Title

Root.title ('Calculator')

4. Size and location

Root.geometry ("295x280+150+150")

5. Transparency

Root.attributes ("- alpha", 0.9)

6. Background

Root ["background"] = "# ffffff"

7. Label

Lable1 = tk.Label (root, textvariable=result_num, width=20, height=2, font= ('Song style', 20), justify='left', background='#ffffff', anchor='se')

8. Overall Arrangement

Lable1.grid (padx=4, pady=4, row=0, column=0, columnspan=4)

9. Button

Button_clear = tk.Button (root, text='C', width=5, font= ('Song', 16), relief='flat', background='#C0C0C0', command=lambda: clear () button_back = tk.Button (root, text=' ←', width=5, font= ('Song', 16), relief='flat', background='#C0C0C0', command=lambda: back () button_division = tk.Button (root, text='/', width=5, font= ('Song', 16), relief='flat', background='#C0C0C0' Command=lambda: operator ('/') button_multiplication = tk.Button (root, text='x', width=5, font= ('Song', 16), relief='flat', background='#C0C0C0', command=lambda: operator ('*') button_clear .grid (padx=4, row=1, column=0) button_back .grid (padx=4, row=1, column=1) button_division .grid (padx=4, row=1, column=2) button_multiplication .grid (padx=4, row=1, column=3) button_seven = tk.Button (root) Text='7', width=5, font= ('Song style', 16), relief='flat', background='#FFDEAD', command=lambda: append_num ('7') button_eight = tk.Button (root, text='8', width=5, font= ('Song style', 16), relief='flat', background='#FFDEAD', command=lambda: append_num ('8') button_nine = tk.Button (root, text='9', width=5, font= ('Song style', 16), relief='flat', background='#FFDEAD' Command=lambda: append_num ('9') button_subtraction = tk.Button (root, text='-', width=5, font= ('Song', 16), relief='flat', background='#C0C0C0', command=lambda: operator ('-') button_seven. Grid (padx=4, row=2, column=0) button_eight. Grid (padx=4, row=2, column=1) button_nine. Grid (padx=4, row=2, column=2) button_subtraction. Grid (padx=4, row=2, column=3) button_four = tk.Button (root Text='4', width=5, font= ('Song', 16), relief='flat', background='#FFDEAD', command=lambda: append_num ('4') button_four.grid (padx=4, pady=4, row=3, column=0) button_five = tk.Button (root, text='5', width=5, font= ('Song', 16), relief='flat', background='#FFDEAD', command=lambda: append_num ('5') button_five.grid (padx=4, row=3, column=1) button_six = tk.Button (root, text='6', width=5) Font= ('Song', 16), relief='flat', background='#FFDEAD', command=lambda: append_num ('6') button_six.grid (padx=4, row=3, column=2) button_addition = tk.Button (root, text='+', width=5, font= ('Song', 16), relief='flat', background='#C0C0C0', command=lambda: operator ('+') button_addition.grid (padx=4, row=3, column=3) button_one = tk.Button (root, text='1', width=5, font= ('Song', 16) Relief='flat', background='#FFDEAD', command=lambda: append_num ('1') button_one.grid (padx=4, row=4, column=0) button_two = tk.Button (root, text='2', width=5, font= ('Song', 16), relief='flat', background='#FFDEAD', command=lambda: append_num ('2') button_two.grid (padx=4, row=4, column=1) button_three = tk.Button (root, text='3', width=5, font= ('Song', 16), relief='flat' Background='#FFDEAD', command=lambda: append_num ('3') button_three.grid (padx=4, row=4, column=2) button_equal = tk.Button (root, text='=', width=5, height=3, font= ('Song', 16), relief='flat', background='#C0C0C0', command=lambda: equal () button_equal.grid (padx=4, row=4, rowspan=5, column=3) button_zero = tk.Button (root, text='0', width=12, font= ('Song', 16), relief='flat', background='#FFDEAD' Command=lambda: append_num ('0') button_zero.grid (padx=4, pady=4, row=5, column=0, columnspan=2) button_decimal = tk.Button (root, text='.', width=5, font= ('Verdana', 16), relief='flat', background='#FFDEAD', command=lambda: append_num ('.') button_decimal.grid (padx=4, row=5, column=2)

Now get the interface effect.

Function

Add a number

Def append_num (I): lists.append (I) result_num.set ('. Join (lists))

Select operation symbol

Def operator (I): if len (lists) > 0: if lists [- 1] in ['+','-','*','/']: lists [- 1] = I else: lists.append (I) result_num.set (''.join (lists))

Zero clearance

Def clear (): lists.clear () result_num.set (0)

Backspace

Def back (): del lists [- 1] result_num.set (lists)

Equal sign

Def equal (): a = '.join (lists) end_num = eval (a) result_num.set (end_num) lists.clear () lists.append (str (end_num))

Define a list to collect input

Lists = [] result_num = tk.StringVar () result_num.set (0)

Finally, run the code, and the effect is as follows

Try it first.

Get the result of the operation

This is the end of the article on "how to use Python to develop a desktop Mini Program". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report