Apr-27-2022, 08:53 PM
(Apr-27-2022, 12:31 AM)53535 Wrote: i made a ui , and converted it into code and add two lines
Why creating an ui? The QtDesigner generates code that you would never write like this.
A menu does not need a setGeometry.
You can also add the two lines for the menu like this.
from PyQt5 import QtCore, QtGui, QtWidgets import sqlite3 from PyQt5.QtWidgets import QMainWindow, QApplication, QFileDialog, QLabel, QAction import os class MyWindow(QMainWindow): def __init__(self): super(MyWindow, self).__init__() self.setGeometry(100, 100, 400, 300) fileMenu = self.menuBar().addMenu('Open') fileMenu.addAction(QAction("open sqlite file", self, triggered = self.get_file_name)) def get_file_name(self): file_filter= "data file (*.sqlite *.sqlite3 *.db)" fname,_ = QFileDialog.getOpenFileName( parent=None, caption="select a file", directory=os.getcwd(), filter=file_filter ) if fname: print(fname) else: print("cancelled") if __name__ == '__main__': import sys app = QApplication(sys.argv) window = MyWindow() window.show() sys.exit(app.exec_())