Python 3 Please help Question #1 Rewrite the convert GUI so that it converts Fah
ID: 3716851 • Letter: P
Question
Python 3 Please help
Question #1
Rewrite the convert GUI so that it converts Fahrenheit temperatures to Celsius temperatures.
I rewrote the GUI but its not working properly. Here is my Program
from graphics import *
def main():
win = GraphWin("Fahrenheit Converter", 400, 300)
win.setCoords(0.0, 0.0, 3.0, 4.0)
win.setBackground('blue')
Text(Point(1,3), "Fahrenheit Temperature:").draw(win)
Text(Point(1,1), " Celsius Temperature:").draw(win)
input = Entry(Point(2,3), 5)
input.setText("0.0")
input.setFill('lime green')
input.draw(win)
output = Text(Point(2,1),"")
output.draw(win)
rect =Rectangle(Point(1,1.5), Point(2,2.5))
rect.draw(win)
button = Text(Point(1.5,2.0),"Convert It")
button.draw(win)
win.getMouse()
fahrenheit = eval(input.getText())
celsius = fahrenheit - 32 * 5/9
output.setText(round(celsius,2))
button.setText("Quit")
p = win.getMouse()
px = p.getX()
py = p.getY()
while not (1 < px < 2 and 1.5 < py < 2.5):
p = win.getMouse()
px = p.getX()
py = p.getY()
win.close()
main()
______________________________________________________________________________________________________________________________________________
QUESTION #2
Modify the circle intersection program so that: (1) the circle is entirely within the window (restrict the length of the radius); and (2) the line intersects the circle (restrict the value of the y-intersect).
Here is the program to modify
from graphics import *
import math
def main():
win = GraphWin('Circle intersection',600,300)
win.setCoords(0,0,24,12)
win.setBackground('White')
chart = Rectangle(Point(1,11),Point(11,1))
chart.setFill('grey')
chart.draw(win)
Line(Point(6,1),Point(6,11)).draw(win)
Line(Point(1,6),Point(11,6)).draw(win)
for i in range(2,23):
i = i/2
Line(Point(0.75,i),Point(1.25,i)).draw(win)
Line(Point(i,10.75),Point(i,11.25)).draw(win)
k = m = 6
for i in range(0,11):
num = Text(Point(0.5,k),i)
num.setSize(6)
num.draw(win)
num2 = Text(Point(k,11.5),i)
num2.setSize(6)
num2.draw(win)
num3 = Text(Point(m,11.5),i*-1)
num3.setSize(6)
num3.draw(win)
num3 = Text(Point(0.5,m),i*-1)
num3.setSize(6)
num3.draw(win)
k = k+0.5
m = m-0.5
intro1 = Text(Point(17.40,10.75),'Program to calculate X value where')
intro1.setStyle('bold')
intro1.draw(win)
intro2 = Text(Point(15.8,10),'Y intersect with a circle')
intro2.setStyle('bold')
intro2.draw(win)
Text(Point(15.75,8.5),'Circle radius (Enter value): ').draw(win)
inputR = Entry(Point(14,7.5), 0)
inputR.setText('0')
inputR.draw(win)
Text(Point(18,6),'Horizontal line int.(Enter value 10 to -10):').draw(win)
inputY = Entry(Point(14,5),10)
inputY.setText('0')
inputY.draw(win)
Text(Point(14.5,3.5),'X intersection at: ').draw(win)
Text(Point(12.2,2.70),'+').draw(win)
Text(Point(12.2,2.25),'-').draw(win)
answerX = Entry(Point(14.5,2.5),10)
answerX.setText('?')
answerX.draw(win)
Fbutton = Rectangle(Point(19,2),Point(23.5,0.5))
Fbutton.setFill('green')
Fbutton.draw(win)
FbuttonT = Text(Point(21.25,1.25),'Find Answer!')
FbuttonT.draw(win)
win.getMouse()
R = eval(inputR.getText())
Y = eval(inputY.getText())
X = math.sqrt(R**2-Y**2)
X = round(X,2)
answerX.setText(X)
R = R/2
resultC = Circle(Point(6,6),R)
resultC.setFill('lightblue')
resultC.draw(win)
Line(Point(6,1),Point(6,11)).draw(win)
Line(Point(1,6),Point(11,6)).draw(win)
Y = Y/2+6
lineY = Line(Point(1,Y),Point(11,Y))
lineY.setFill('darkgreen')
lineY.draw(win)
X = X/2
Xa = X+6
Xb = 6-X
resultPa = Circle(Point(Xa,Y),0.1)
resultPa.setFill('red')
resultPa.draw(win)
resultPb = Circle(Point(Xb,Y),0.1)
resultPb.setFill('red')
resultPb.draw(win)
FbuttonT.setText('Quit')
win.getMouse()
win.close()
main()
Explanation / Answer
#import
#main function
from tkinter import *
def main():
root=Tk()
root.title("Some GUI")
root.geometry("400x700")
#someothersting=""
someotherstring=""
#enter Celcius
L1=Label(root,text="Enter a Celcius temperature.")
E1=Entry(root,textvariable=someotherstring)
somebutton=Button(root, text="Total", command=lambda: convert(E1.get()))
somebutton.pack()
E1.pack()
L1.pack()
root.mainloop()#main loop
#convert Celcius to Fahrenheit
def convert(somestring):
if somestring != "":
cel=int(somestring)
far=(9/5*(cel))+32
print(far)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.