0
    from tkinter import *                 
    import plotly.graph_objects as go
    root = Tk()   
    root.geometry("1300x700")
    mapbox_access_token ="pk.eyJ1Ijoidml2ZWtrdW1hcmxhbCIsImEiOiJjazdoZDI2enkwOTBiM21sbGpubnQwN3g4In0.ClK-bWxExBsMOcHoyvcrXg"
        
    fig = go.Figure(go.Scattermapbox(
                lat=['45.5017'],
                lon=['-73.5673'],
                mode='markers',
                marker=go.scattermapbox.Marker(
                    size=14
                ),
                text=['Montreal'],
            ))
        
    fig.update_layout(
            hovermode='closest',
            mapbox=dict(
                accesstoken=mapbox_access_token,
                bearing=0,
                center=go.layout.mapbox.Center(
                    lat=45,
                    lon=-73
                ),
                pitch=0,
                zoom=5
            )
        )
    fig.place(width=600, x=0, y=25)
    fig.show()
    mainloop() 

I tried to display mapbox in tkinter but getting errors.

AttributeError                            Traceback (most recent call last)
<ipython-input-16-3312bf82150d> in <module>
     28         )
     29     )
---> 30 fig.place(width=600, x=0, y=25)
     31 fig.show()
     32 mainloop()

AttributeError: 'Figure' object has no attribute 'place'

The code without tkinter is running perfect on jupyter notebook. but want to know how to display it in tkinter.

5
  • "but getting errors" is too vague, please include the error messages in the question. Commented Jul 15, 2020 at 7:19
  • @j_4321 -- I have edited the question with error message please check. Commented Jul 15, 2020 at 8:13
  • You are getting this error because your fig object has no place() method, this is not a tkinter widget. According to stackoverflow.com/questions/38426263/…, I don't think it is possible to embed a plotly graph in a tkinter window (while it is possiblle in a jupyter notebook). Commented Jul 15, 2020 at 8:55
  • @j_4321 Is there any alternative for showing mapbox in tkinter, any solution will be welcome. Commented Jul 15, 2020 at 9:27
  • I don't know anything about plotly or mapbox. What is possible for sure is to display a static map as an image in tkinter. Commented Jul 15, 2020 at 10:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.