no resizable window + error when images aren't in same ratio w/h
This commit is contained in:
parent
7cd33f688e
commit
43ed99169a
1 changed files with 16 additions and 1 deletions
17
soui.py
17
soui.py
|
@ -2,6 +2,7 @@ import numpy as np
|
||||||
import sounddevice as sd
|
import sounddevice as sd
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from tkinter import Tk, Canvas, Label, PhotoImage
|
from tkinter import Tk, Canvas, Label, PhotoImage
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
speaking = False
|
speaking = False
|
||||||
|
|
||||||
|
@ -29,6 +30,16 @@ class Affichage:
|
||||||
self.speaking = "speaking.png"
|
self.speaking = "speaking.png"
|
||||||
self.notspeaking = "not_speaking.png"
|
self.notspeaking = "not_speaking.png"
|
||||||
|
|
||||||
|
def get_ratio_img(self):
|
||||||
|
image = Image.open(self.speaking)
|
||||||
|
image2 = Image.open(self.notspeaking)
|
||||||
|
width, height = image.size
|
||||||
|
width2, height2 = image2.size
|
||||||
|
if width != width2 or height != height2:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
return f"{width}x{height}"
|
||||||
|
|
||||||
def refresh(self):
|
def refresh(self):
|
||||||
self.get_image()
|
self.get_image()
|
||||||
self.label.config(image = self.img)
|
self.label.config(image = self.img)
|
||||||
|
@ -44,7 +55,11 @@ class Affichage:
|
||||||
def start(self):
|
def start(self):
|
||||||
self.fenetre = Tk()
|
self.fenetre = Tk()
|
||||||
self.fenetre.title('Microphone')
|
self.fenetre.title('Microphone')
|
||||||
self.fenetre.geometry("357x697")
|
geo = self.get_ratio_img()
|
||||||
|
if not geo:
|
||||||
|
raise NameError("Sorry, images speaking and not_speaking don't have same ratio")
|
||||||
|
self.fenetre.geometry(geo)
|
||||||
|
self.fenetre.resizable(0, 0)
|
||||||
self.get_image()
|
self.get_image()
|
||||||
self.label = Label(self.fenetre, image = self.img)
|
self.label = Label(self.fenetre, image = self.img)
|
||||||
self.label.pack(fill = "both", expand = "yes")
|
self.label.pack(fill = "both", expand = "yes")
|
||||||
|
|
Reference in a new issue