create account

Raspberry-Pi Programming Efforts by bashadow

View this thread on: hive.blogpeakd.comecency.com
· @bashadow ·
$0.96
Raspberry-Pi Programming Efforts
December 8<sup>th</sup>, 2020

<div class="text-justify">

<center><h2>Efforts to Learn</h2></center>
I have been slowly trying to learn to program using my Raspberry-Pi. I've learned a little bit about guizero, I can make a "Wanted Poster" and almost actually understand how I did it and why it worked. (see <a href="https://peakd.com/hive-163521/@bashadow/raspberry-pi-update-a-week-and-a-couple-of-days">Last post</a>)

Through it I learned how to change colors and fonts and font size and how to import pictures.

Now I am trying to learn how to make something functional. One of the Links that @mytechtrail provided me was to Real Python Tutorial <a href="https://realpython.com/python-gui-tkinter/">Python GUI Programming With Tkinter</a>. Contained in that was a temperature conversion example:

![real python temp coversion program](https://files.peakd.com/file/peakd-hive/bashadow/dyiZSKCA-real20python20temp20coversion20image.png)

I played around with it quite a bit the last couple of days and this is my incomplete version with a few modifications that I learned:

![my temp coversion so far.png](https://files.peakd.com/file/peakd-hive/bashadow/hPdoEEbn-my20temp20coversion20so20far.png)

*Real Python* version is a fixed size window, that when you type a number in the Celsius symbol will shift and a label will hold the conversion when you click the arrow button.

One of the first things I modified was making the window re- sizable along the horizontal, `window.resizable(width=True, height=False)` (which in the finished version I will likely go back to false for resize option). I also played with the background colors as practice. It did take me some research to find out how to change the main window background color.
 
Where `bg="color"` worked for the button and the label, it did not work for setting the window color, however I did find `.configure(bg="salmon")` command that let me change the color. I still do not understand why `bg="color"` would not work so a comment if you can explain would be appreciated. Is it a global seting verse a local setting thing?

Now about the **Reset** button. I want that to clear the input box and to give it the focus when the button is pushed. 
```
btn_clear = tk.Button(text="Reset")
#ent_temperature.entry.delete(0, tk.end)
```
That is what I have for now, it does not clear the input box.

Below is my modified code, followed by the Real python code example.

<hr>

```

import tkinter as tk

#gui.configure(bg='blue')


def fahrenheit_to_celsius():
    """Convert the value for Fahrenheit to Celsius and insert the
    result into lbl_result.
    """
    fahrenheit = ent_temperature.get()
    celsius = (5/9) * (float(fahrenheit) - 32)
    lbl_result["text"] = f"{round(celsius, 2)} \N{DEGREE CELSIUS}"

# Set-up the window
window = tk.Tk()
window.title("Temperature Converter")
window.resizable(width=True, height=False)
window.configure(bg="salmon")
# Create the Fahrenheit entry frame with an Entry
# widget and label in it
frm_entry = tk.Frame(master=window)
ent_temperature = tk.Entry(master=frm_entry, width=5)
lbl_temp = tk.Label(master=frm_entry, text="\N{DEGREE FAHRENHEIT}")

# Layout the temperature Entry and Label in frm_entry
# using the .grid() geometry manager
ent_temperature.grid(row=0, column=0, sticky="e")
lbl_temp.grid(row=0, column=1, sticky="w")

# Create the conversion Button and result display Label
btn_convert = tk.Button(
    master=window,
    text="\N{RIGHTWARDS BLACK ARROW}",
    command=fahrenheit_to_celsius,
    bg="yellow"
)
lbl_result = tk.Label(master=window, text=" \N{DEGREE CELSIUS}", bg="lightblue",
                      width=7)

btn_clear = tk.Button(text="Reset")
#ent_temperature.entry.delete(0, tk.end)

# Set-up the layout using the .grid() geometry manager
frm_entry.grid(row=0, column=0, padx=10)
btn_convert.grid(row=0, column=1, pady=10)
lbl_result.grid(row=0, column=2, padx=15)
btn_clear.grid(row=0, column=3, padx=10)

# Run the application
window.mainloop()
```

<hr>

Real python Code:
```
import tkinter as tk

def fahrenheit_to_celsius():
    """Convert the value for Fahrenheit to Celsius and insert the
    result into lbl_result.
    """
    fahrenheit = ent_temperature.get()
    celsius = (5/9) * (float(fahrenheit) - 32)
    lbl_result["text"] = f"{round(celsius, 2)} \N{DEGREE CELSIUS}"

# Set-up the window
window = tk.Tk()
window.title("Temperature Converter")
window.resizable(width=False, height=False)

# Create the Fahrenheit entry frame with an Entry
# widget and label in it
frm_entry = tk.Frame(master=window)
ent_temperature = tk.Entry(master=frm_entry, width=10)
lbl_temp = tk.Label(master=frm_entry, text="\N{DEGREE FAHRENHEIT}")

# Layout the temperature Entry and Label in frm_entry
# using the .grid() geometry manager
ent_temperature.grid(row=0, column=0, sticky="e")
lbl_temp.grid(row=0, column=1, sticky="w")

# Create the conversion Button and result display Label
btn_convert = tk.Button(
    master=window,
    text="\N{RIGHTWARDS BLACK ARROW}",
    command=fahrenheit_to_celsius
)
lbl_result = tk.Label(master=window, text="\N{DEGREE CELSIUS}")

# Set-up the layout using the .grid() geometry manager
frm_entry.grid(row=0, column=0, padx=10)
btn_convert.grid(row=0, column=1, pady=10)
lbl_result.grid(row=0, column=2, padx=10)

# Run the application
window.mainloop()
```

<hr>

Any help, (or guidance where to find the answer), figuring out the **Reset** button I want would be appreciated. It is a slow process, but I do feel like I am making some headway.

<center><sub>Tiny Picture links back to my blog:</sub></center><center><a href="https://peakd.com/@bashadow"><img src=https://images.hive.blog/100x50/https://files.peakd.com/file/peakd-hive/bashadow/CSiw0Xl5-avatar3.png></a></center>

</div>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 105 others
properties (23)
authorbashadow
permlinkraspberry-pi-programming-efforts
categoryhive-142614
json_metadata"{"app":"peakd/2020.11.4","format":"markdown","description":"A Raspberry-Pi Tkinter \"how to\" programming question. On-line self learning is not easy when there is no one to ask a ?","tags":["help","helprequest","learning","howto","question","programming","python","tkinter","oc","archon"],"users":["bashadow","mytechtrail"],"links":["/hive-163521/@bashadow/raspberry-pi-update-a-week-and-a-couple-of-days","/@mytechtrail","https://realpython.com/python-gui-tkinter/","/@bashadow"],"image":["https://files.peakd.com/file/peakd-hive/bashadow/dyiZSKCA-real20python20temp20coversion20image.png","https://files.peakd.com/file/peakd-hive/bashadow/hPdoEEbn-my20temp20coversion20so20far.png","https://images.hive.blog/100x50/https://files.peakd.com/file/peakd-hive/bashadow/CSiw0Xl5-avatar3.png"]}"
created2020-12-09 00:50:33
last_update2020-12-09 00:50:33
depth0
children8
last_payout2020-12-16 00:50:33
cashout_time1969-12-31 23:59:59
total_payout_value0.528 HBD
curator_payout_value0.430 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5,765
author_reputation100,388,692,638,882
root_title"Raspberry-Pi Programming Efforts"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id100,873,474
net_rshares6,304,341,760,844
author_curate_reward""
vote details (169)
@bdmillergallery ·
I'm impressed. I find it very hard for my non trained brain to learn such things, but the more I play around with it, the more I understand and retain. Looks like your plugging away and learning stuff. Good luck with figuring it all out and having fun in the meantime.
properties (22)
authorbdmillergallery
permlinkre-bashadow-ql7gap
categoryhive-142614
json_metadata{"tags":["hive-142614"],"app":"peakd/2020.11.4"}
created2020-12-12 02:30:15
last_update2020-12-12 02:30:15
depth1
children1
last_payout2020-12-19 02:30:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length268
author_reputation651,220,827,845,993
root_title"Raspberry-Pi Programming Efforts"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id100,916,743
net_rshares0
@bashadow ·
I do find it fun to try and focus on figuring something out but I can get lost for hours which isn't a bad thing being retired and all, but then I end up with less time on other things. But it does keep the brain functioning better than Amazon videos. 
properties (22)
authorbashadow
permlinkre-bdmillergallery-ql7p2a
categoryhive-142614
json_metadata{"tags":["hive-142614"],"app":"peakd/2020.11.4"}
created2020-12-12 05:39:36
last_update2020-12-12 05:39:36
depth2
children0
last_payout2020-12-19 05:39:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length252
author_reputation100,388,692,638,882
root_title"Raspberry-Pi Programming Efforts"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id100,917,949
net_rshares0
@beerlover ·
You need to stake more BEER (24 staked BEER allows you to call BEER one time per day)
properties (22)
authorbeerlover
permlinkre-raspberry-pi-programming-efforts-20201210t022423z
categoryhive-142614
json_metadata"{"app": "beem/0.23.11"}"
created2020-12-10 02:24:30
last_update2020-12-10 02:24:30
depth1
children0
last_payout2020-12-17 02:24:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length85
author_reputation25,781,827,182,727
root_title"Raspberry-Pi Programming Efforts"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id100,888,439
net_rshares0
@kansuze ·
Looks like you're having some fun! What ultimately are you planning to do with your Raspberry Pi?
properties (22)
authorkansuze
permlinkql3iyf
categoryhive-142614
json_metadata{"app":"hiveblog/0.1"}
created2020-12-09 23:37:27
last_update2020-12-09 23:37:27
depth1
children1
last_payout2020-12-16 23:37:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length97
author_reputation81,503,937,847,895
root_title"Raspberry-Pi Programming Efforts"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id100,886,681
net_rshares0
@bashadow ·
$0.03
I plan on it being my major on line computer in the future, for now I am using it to learn how to do some programming.
👍  ,
properties (23)
authorbashadow
permlinkre-kansuze-ql3ma8
categoryhive-142614
json_metadata{"tags":["hive-142614"],"app":"peakd/2020.11.4"}
created2020-12-10 00:49:15
last_update2020-12-10 00:49:15
depth2
children0
last_payout2020-12-17 00:49:15
cashout_time1969-12-31 23:59:59
total_payout_value0.014 HBD
curator_payout_value0.014 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length118
author_reputation100,388,692,638,882
root_title"Raspberry-Pi Programming Efforts"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id100,887,376
net_rshares239,293,913,329
author_curate_reward""
vote details (2)
@pixresteemer ·
<center>![pixresteemer_incognito_angel_mini.png](https://files.peakd.com/file/peakd-hive/pixresteemer/8h7BBw1w-pixresteemer_incognito_angel_mini.png)</center><center>Bang, I did it again... I just rehived your post!</center><center>Week 35 of my [contest](/hive-179017/@pixresteemer/the-re-hive-contest-results-week-34-and-start-week-35) just started...you can now check the winners of the previous week!</center><center>!BEER</center><center><sub>7</sub></center>
properties (22)
authorpixresteemer
permlink20201209t005741997z
categoryhive-142614
json_metadata{"tags":["pixresteemer"],"app":"pixresteemer"}
created2020-12-09 00:57:42
last_update2020-12-09 00:57:42
depth1
children0
last_payout2020-12-16 00:57:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length464
author_reputation121,293,160,978,048
root_title"Raspberry-Pi Programming Efforts"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id100,873,538
net_rshares0
@redheadpei ·
It seems complicated. Good you are making headway with the program.
properties (22)
authorredheadpei
permlinkre-bashadow-ql56qd
categoryhive-142614
json_metadata{"tags":["hive-142614"],"app":"peakd/2020.11.4"}
created2020-12-10 21:08:36
last_update2020-12-10 21:08:36
depth1
children1
last_payout2020-12-17 21:08:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length67
author_reputation173,345,999,152,071
root_title"Raspberry-Pi Programming Efforts"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id100,900,277
net_rshares0
@bashadow ·
It is a simple typo can be hard to find, and finding help is sometimes not easy for a real beginner like myself.
properties (22)
authorbashadow
permlinkre-redheadpei-ql5jze
categoryhive-142614
json_metadata{"tags":["hive-142614"],"app":"peakd/2020.11.4"}
created2020-12-11 01:54:42
last_update2020-12-11 01:54:42
depth2
children0
last_payout2020-12-18 01:54:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length112
author_reputation100,388,692,638,882
root_title"Raspberry-Pi Programming Efforts"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id100,902,683
net_rshares0