0

I´m a newbie in programming, and I was looking for some code or tutorial on how to make a clickable image in python without the Tkinter library, but I didn´t found anyone. Anyway, I´m trying to make a music player in a game where you have to guess the name of song with hints like a short melody, but I need to click the "play.png" to play the melody and I don´t know how. Can anybody help me with this? Thanks a lot

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • What do you mean by 'clickable image in python without the Tkinter library' –  May 26 '21 at 17:32
  • You're going to have to use _some_ GUI framework. Tkinter is just one of several that are available and is included with the distribution (you will need to download and install one of the others to use it). – martineau May 26 '21 at 18:28
  • Why are you against using tkinter? Are you wanting to do this without _any_ GUI toolkit? – Bryan Oakley May 27 '21 at 20:59
  • I´m against Tkinter because it will create a new window, but I already have a window, and I want to add the play button to the screen I already have and don´t create a new one. I hope that you understand – Martin Hrouda May 30 '21 at 08:18

1 Answers1

0

As it was mentioned in the comments, there are several GUI frameworks or toolskits available other than Tkinter.

Here is a simple example using viaduc and adapting its helloworld.py.

#!/usr/bin/env python3
from viaduc import Viaduc


class Presentation(Viaduc.Presentation):
    title = 'audio player'
    width = 496
    height = 336
    html = '''
<!DOCTYPE html>
<html lang="en">
  <head>
    {{bootstrap_meta}}
    {{bootstrap_css}}
    <title>{{title}}</title>
  </head>
  <body>
    {{frameless_close_button}}
    <div class="jumbotron">
        <h1>{{title}}</h1>
        <p class="lead">Welcome to <em>Viaduc</em>, the simplest way of creating a GUI in python.</p>
    </div>
    <div class="mx-auto" style="width: 90%;">
        <audio src="https://samplelib.com/lib/preview/mp3/sample-6s.mp3" controls="" controlslist="nodownload" style="width:100%"></audio>
    </div>
    {{bootstrap_js}}
  </body>  
 </html>
'''


if __name__ == '__main__':
    Viaduc(presentation=Presentation(), args=['', '--frameless'])

which produces

enter image description here

and can play the audio sample.

Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134