(15 points) Problem 2 gives you practice with interactive graphics that use mouse clicks rather than the console to get user input. It also gives your practice using coordinate transformation to make placing text in the window easier.
Hint: To create labels that combine text and numerical values, you may find using the type conversion function str() helpful. For more, see page 152 of the textbook (2nd edition page 146).
Submit your responses to Problem 2 as two separate modules (line1.py and line2.py).
a. (10 points) Write a program line1.py as described in Programming Exercise 8 on page 127 of the textbook (2nd edition page 119).
b. (5 points) Modify your program from part (a) so you have a second program named line2.py. This program will have the midpoint labeled, offset slightly from the actual location of the midpoint of the line

Respuesta :

Below is the code for the given question in which are working with interactive graphics that use mouse clicks rather than the console to get user input.

Coding Part:

from tkinter import *

from tkinter.filedialog

import askopenfilename from PIL import Image, ImageTk

import tkinter.simpledialog  root = Tk()  

#setting up a tkinter canvas

w = Canvas(root, width=1000, height=1000) w.pack()  

#adding the image

File = askopenfilename(parent=root, initialdir="./",title='Select an image')

original = Image.open(File) original = original.resize((1000,1000)) #resize

image img = ImageTk.PhotoImage(original) w.create_image(0, 0,

image=img, anchor="nw")

#ask for the temperature and pressure extent

xmt = tkinter.simpledialog.askfloat("Temperature", "degrees in x-axis")

ymp = tkinter.simpledialog.askfloat("Pressure", "bars in y-axis")  

#ask for real PT values at origin

xc = tkinter.simpledialog.askfloat("Temperatures", "Temperatures at origin") yc = tkinter.simpledialog.askfloat("Pressure", "Pressure at origin")  #instruction on 3 point selection to define grid

tkinter.messagebox.showinfo("Instructions", "Click: \n"                                              "1) Origin \n"                                            

"2) Temperature end \n"                                            

"3) Pressure end")    

global x0,y0    

x0 = eventorigin.x    

y0 = eventorigin.y    

print(x0,y0)    

w.bind("<Button 1>",getextentx)

#mouseclick event w.bind("<Button 1>",getorigin)  

# Determine the extent of the figure in the x direction (Temperature) def getextentx(eventextentx):    

global xe    

xe = eventextentx.x    

print(xe)    

w.bind("<Button 1>",getextenty)  

global ye    

ye = eventextenty.y    

print(ye)    

tkinter.messagebox.showinfo("Grid", "Grid is set. You can start picking coordinates.")    

w.bind("<Button 1>",printcoords)  

#Coordinate transformation into Pressure-Temperature space def printcoords(event):    

xmpx = xe-x0    

xm = xmt/xmpx    

ympx = ye-y0    

ym = -ymp/ympx      

#coordinate transformation    

newx = (event.x-x0)*(xm)+xc    

newy = (event.y-y0)*(ym)+yc      

To know more about interactive graphics, visit: https://brainly.com/question/18068928

#SPJ4

RELAXING NOICE
Relax