1 Star 0 Fork 0

mamh-mixed/python-cookbook

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
Letter_Counter.py 1.44 KB
Copy Edit Raw Blame History
slowy07 authored 2022-01-30 09:33 +08:00 . refactor: clean code
import tkinter as tk
root = tk.Tk()
root.geometry("400x260+50+50")
root.title("Welcome to Letter Counter App")
message1 = tk.StringVar()
Letter1 = tk.StringVar()
def printt():
message = message1.get()
letter = Letter1.get()
message = message.lower()
letter = letter.lower()
# Get the count and display results.
letter_count = message.count(letter)
a = "your message has " + str(letter_count) + " " + letter + "'s in it."
labl = tk.Label(root, text=a, font=("arial", 15), fg="black").place(x=10, y=220)
lbl = tk.Label(root, text="Enter the Message--", font=("Ubuntu", 15), fg="black").place(
x=10, y=10
)
lbl1 = tk.Label(
root, text="Enter the Letter you want to count--", font=("Ubuntu", 15), fg="black"
).place(x=10, y=80)
E1 = tk.Entry(
root, font=("arial", 15), textvariable=message1, bg="white", fg="black"
).place(x=10, y=40, height=40, width=340)
E2 = tk.Entry(
root, font=("arial", 15), textvariable=Letter1, bg="white", fg="black"
).place(x=10, y=120, height=40, width=340)
but = tk.Button(
root,
text="Check",
command=printt,
cursor="hand2",
font=("Times new roman", 30),
fg="white",
bg="black",
).place(x=10, y=170, height=40, width=380)
# print("In this app, I will count the number of times that a specific letter occurs in a message.")
# message = input("\nPlease enter a message: ")
# letter = input("Which letter would you like to count the occurrences of?: ")
root.mainloop()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mamh-mixed/python-cookbook.git
git@gitee.com:mamh-mixed/python-cookbook.git
mamh-mixed
python-cookbook
python-cookbook
master

Search