(Recasts paragraph 1-2,5-7 with Tusk's comments in Prague, adds estimated number of protesters in paragraph 8)

WARSAW, Feb 27 (Reuters) - Polish Prime Minister Donald Tusk said on Tuesday he could not rule out widening a national ban on imports of Ukrainian grains to other products if the European Union does not act to protect the bloc's markets.

Tusk made the remarks during a visit to Prague as thousands of Polish farmers took to the streets of Warsaw, carrying the national flag and blowing handheld horns, escalating a protest against food imports from Ukraine and EU green rules.

Farmers across Europe have been protesting for weeks against constraints placed on them by the EU's 'Green Deal' regulations meant to tackle climate change, as well as rising costs and what they say is unfair competition from outside the EU, particularly Ukraine.

Poland last year extended a ban on Ukrainian grain imports.

"We are talking about it with the Ukrainian side - that it will be necessary to expand the embargo to other products if the European Union does not find more effective ways to protect the European and Polish markets," Tusk said on Tuesday.

Earlier in the day, Tusk said that the EU had to solve the problems created by its decision to open its borders to imports of Ukrainian food products after Russia invaded its neighbour in early 2022.

He added that Poland was ready to co-finance purchases of Polish, European and Ukrainian food and agricultural products to be sent as humanitarian aid to famine-stricken countries, and that "Europe should certainly find funds for this."

Back home, farmers rallied in central Warsaw before marching towards parliament and then Tusk's office. A city hall official cited by PAP state news agency put the number of protesters around 10,000.

"We are protesting because we want the 'green deal' to be lifted, as it will lead our farms to bankruptcy with its costs... that are not comparable to what we harvest and to what we are paid," said Kamil Wojciechowski, 31, a farmer from Izbica Kujawska in central Poland.

"And ... what we're paid for our work, it has decreased because of the influx of grain from Ukraine and this is our second demand - to block the influx of grain from Ukraine."

The farmers began a series of protests throughout the country earlier this month, which included a near-total blockade of all Ukrainian border crossings, as well as disruptions at ports and on roads nationwide.

"We won't give up. We have no choice. Our farms will go bankrupt, we will lose our livelihoods," Pawel Walkowiak, 47, a corn and wheat producer from Konarzewo in western Poland said.

The city hall official said Tuesday's protest in Warsaw took place without major incidents.

(Reporting by Karol Badohal, Kuba Stezycki and Anna Wlodarczak-Semczuk in Warsaw and Jan Lopatka in Prague; Editing by Emelia Sithole-Matarise)